Commit 3d32c2d8 3d32c2d8dddeb912dd910d902865b3631d1ef50d by xianghan@topdraw.cn

初始化项目

;
1 parent 35b568f7
Showing 268 changed files with 16023 additions and 0 deletions
1 # 积分台账表
2 CREATE TABLE `uc_points_standing_book` (
3 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
4 `points_produce` bigint(20) NOT NULL COMMENT '积分生产',
5 `points_consume` bigint(20) NOT NULL COMMENT '积分消耗',
6 `points_available` bigint(20) NOT NULL COMMENT '可用总积分',
7 `points_expire` bigint(20) NOT NULL COMMENT '积分过期',
8 `day` varchar(16) DEFAULT NULL COMMENT '日期',
9 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
10 `update_time` datetime DEFAULT NULL COMMENT '创建时间',
11 PRIMARY KEY (`id`)
12 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分台账表';
13
14 # 永久权益表
15 CREATE TABLE `uc_permanent_rights` (
16 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
17 `code` varchar(64) NOT NULL COMMENT '标识',
18 `name` varchar(255) NOT NULL COMMENT '名称',
19 `type` tinyint(4) DEFAULT NULL COMMENT '永久权益类型 0:vip;1:会员等级',
20 `level` tinyint(4) DEFAULT NULL COMMENT '等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index)',
21 `item_discount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商品折扣,10代表10% off,范围为0-100',
22 `extra_points` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '额外积分比率,范围为0-1000',
23 `ad_disabled` tinyint(4) NOT NULL DEFAULT '0' COMMENT '免广告',
24 `extra_activity_ticket` tinyint(4) NOT NULL DEFAULT '0' COMMENT '额外活动参与机会',
25 `free_trial` tinyint(4) NOT NULL DEFAULT '0' COMMENT '免费试看',
26 `zone_sds` tinyint(4) NOT NULL DEFAULT '0' COMMENT '上电视专区权益',
27 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
28 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
29 PRIMARY KEY (`id`)
30 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='永久权益表';
31
32 CREATE TABLE `uc_points_standing_book` (
33 `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
34 `points_produce` bigint NOT NULL COMMENT '积分生产',
35 `points_consume` bigint NOT NULL COMMENT '积分消耗',
36 `points_available` bigint NOT NULL COMMENT '可用总积分',
37 `points_expire` bigint NOT NULL COMMENT '积分过期',
38 `day` varchar(16) DEFAULT NULL COMMENT '日期',
39 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
40 `update_time` datetime DEFAULT NULL COMMENT '创建时间',
41 PRIMARY KEY (`id`)
42 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='积分台账表'
43
44 #优惠券表
45 CREATE TABLE `m_coupon` (
46 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
47 `code` varchar(64) NOT NULL COMMENT '标识',
48 `title` varchar(255) NOT NULL COMMENT '名称',
49 `images` varchar(1024) DEFAULT NULL COMMENT '图片',
50 `stock` int(11) DEFAULT '-1' COMMENT '发行量,-1代表不限量',
51 `remain_stock` int(11) '-1' NULL COMMENT '剩余量,-1代表不限量',
52 `use_type` tinyint(4) DEFAULT '1' COMMENT '优惠形式:1:金额;2:折扣',
53 `denomination` decimal(10,2) DEFAULT NULL COMMENT '面额',
54 `discount` decimal(10,2) DEFAULT NULL COMMENT '折扣',
55 `user_range` tinyint(4) DEFAULT '2' COMMENT '适用用户范围:1:新用户;2:全体用户;3:指定用户分组',
56 `groups` varchar(1024) DEFAULT NULL COMMENT '用户分组,逗号分隔',
57 `collect_limit` tinyint(4) DEFAULT '1' COMMENT '限领次数 -1:无限次; >0:具体次数',
58 `threshold_type` tinyint(4) DEFAULT '1' COMMENT '适用门槛:1:无门槛;2:满减形式',
59 `amount_threshold` decimal(10,2) DEFAULT null COMMENT '满减门槛',
60 `item_range` tinyint(4) DEFAULT '1' COMMENT '产品范围:1:全部商品;2:指定商品',
61 `effect_type` tinyint(4) DEFAULT null COMMENT '生效形式:1:固定日期;2:相对日期',
62 `start_time` datetime DEFAULT NULL COMMENT '生效时间',
63 `expire_time` datetime DEFAULT NULL COMMENT '过期时间',
64 `valid_days` int(11) DEFAULT NULL COMMENT '自领取当日,几天内有效',
65 `description` varchar(255) DEFAULT NULL COMMENT '使用说明',
66 `status` tinyint(4) DEFAULT null COMMENT '状态 0:未开始,1:启用;2:停用',
67 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
68 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
69 PRIMARY KEY (`id`)
70 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=' 优惠券表';
71
72
73 #优惠券
74 CREATE TABLE `m_coupon_history` (
75 `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
76 `coupon_id` bigint DEFAULT NULL COMMENT '优惠券id',
77 `user_id` bigint DEFAULT NULL COMMENT '领券用户id',
78 `coupon_code` varchar(64) DEFAULT NULL COMMENT '优惠券code',
79 `user_nickname` varchar(255) DEFAULT NULL COMMENT '领取人昵称',
80 `receive_time` datetime DEFAULT NULL COMMENT '领取时间',
81 `expire_time` datetime DEFAULT NULL COMMENT '失效时间',
82 `use_status` int DEFAULT NULL COMMENT '使用状态 0:未使用;1:已使用;-1:已过期',
83 `use_time` datetime DEFAULT NULL COMMENT '使用时间',
84 `order_detail_id` bigint DEFAULT NULL COMMENT '订单详情id',
85 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
86 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
87 PRIMARY KEY (`id`) USING BTREE,
88 KEY `idx_member_id` (`user_id`) USING BTREE,
89 KEY `idx_coupon_id` (`coupon_id`) USING BTREE
90 ) ENGINE=InnoDB AUTO_INCREMENT=134 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='优惠券领取、使用历史记录表'
...\ No newline at end of file ...\ No newline at end of file
1
2
3 m_coupon
4 m_coupon_history
5
6 tr_rights
7 tr_rights_histroy
8
9 tr_task
10 tr_task_template
11
12 uc_exp_history
13 uc_exp_detail
14
15 uc_permanent_rights
16
17 uc_member_related_info
18 uc_member_address
19 uc_member_profile
20 uc_member_level
21 uc_member
22
23 uc_points_standing_book
24 uc_points_available
25 uc_points_detail_history
26 uc_points_detail
27
28
29 uc_user_weixin
30 uc_user_tv
...\ No newline at end of file ...\ No newline at end of file
1 ## 会员系统概要设计和细化分解
2
3 ### <font color='darkblue'>建设目的与背景</font>
4
5 建立<font color='red'>融合、跨平台</font>的会员体系,对IPTV、互联网App、移动终端平台进行统一会员管理。对用户体系实现<font color='red'>统一的会员认证</font>,有效管理全平台会员数据。融合<font color='red'>用户中心、Boss系统、商城服务体系、活动系统、任务权益体系、积分/成长体系、会员画像系统</font>,提供多元化的产品形态,打造会员体系与运营模式的智能化平台,通过智能化的分析,把会员与平台的影片、产品、活动、增值业务等建立深度的联系,提高平台的服务能力,推动用户业务的使用,并为产品运营提供强有力的支撑。
6
7 ### <font color='darkblue'>近期目标交付</font>
8
9 #### 四川金熊猫OMO
10
11 ##### <font color='forestgreen'>核心需求</font>
12
13 - 核心是小屏
14
15 - 会员权益体系,不同vip会员,权益不同,向下覆盖(核心是不同vip标识,弱化会员等级)
16 - 主推主题活动
17 - 报名环节(报名费,会员差异,商品关联)
18 - 参与环节(ugc上载,审核,证书)
19 - 数据环节(数据统计)
20 - 积分体系,暂时只对应商城
21
22 #### 重数会员系统
23
24 ##### <font color='forestgreen'>核心需求</font>
25
26 - 核心是大屏(至少短时间是大屏)
27 - 重点关注会员成长体系、会员积分体系,注重会员等级,vip标识可能唯一
28 - 任务权益体系
29 - 积分商城
30
31 ### <font color='darkblue'>整体架构</font>
32
33 >整个会员系统由用户中心、Boss系统、商城系统、活动系统、用户画像系统组成,他们的整体架构如下:
34
35
36
37 ### <font color='darkblue'>User Center</font>
38
39 > 用户中心,是整个会员系统的核心,负责用户的统一登录、鉴权、积分及权益
40
41 #### 用户/账号体系(多屏账号)
42
43 > 账号:各业务系统拥有的<font color='red'>独立的账号体系</font>,如大屏的iptv账号,微信的openid或unionid,移动端app的账号
44
45 > 用户:对应“自然人”的概念,<font color='red'>为了实现跨屏账号体系而抽象的用户概念</font>,是会员体系的依附(会员是特殊身份的用户)
46
47
48
49 ##### <font color='forestgreen'>会员概要(等级/vip)</font>
50
51 - 会员是特殊的一类用户,本质上也是用户
52 - 成为会员的方式
53 - 购买会员
54 - 订阅、关注
55 - 。。。
56 - 会员vip标识
57 - 支持不同层级vip的界定,差异化服务
58 - vip专享权益
59 - 与会员等级独立,两个维度
60 - 会员等级
61 - 通过会员成长值驱动,不依赖于会员购买
62 - 基于等级的权益体系
63 - 会员的生效状态
64 - 满足条件成为会员
65 - 不满足条件会员失效
66 - 使用vip标识来实现
67 - 会员和成长值的关系
68 - 无直接联系
69 - 会员的成长值加速
70 - 会员等级和成长值加速的关系
71
72 ##### <font color='forestgreen'>会员信息</font>
73
74 - 基本信息
75 - 注册时间、注册手机号、性别、会员等级、会员积分、会员余额等
76 - 地址信息
77 - 收货地址
78 - 积分信息
79 - 变动明细
80 - 优惠券信息
81 - 优惠券明细及状态,优惠券金额、使用条件、领取时间、使用时间、有效期及使用状态等
82 - 优惠券的信息一般和账户挂钩,此处需要关联查询
83 - 订单信息
84 - 用户对应账号的订单列表
85 - 子女信息
86 - 子女姓名,身份证,年龄
87
88
89
90 #### (会员)成长体系
91
92 > <font color='red'>成长值</font>:作为会员成长体系中的核心数据,是贯穿整个会员体系重要依据之一。它直接或间接和会员等级、会员权益相关。
93
94 ![image-20210927114350241](https://cy-topdraw.oss-cn-shanghai.aliyuncs.com/typora/20210927114350.png)
95
96 ##### <font color='forestgreen'>成长值的来源</font>
97
98 - 日常登录
99 - 观影
100 - 参与活动
101 - 订购
102 - 后台赠送
103 - ...
104
105 ##### <font color='forestgreen'>成长值的消耗</font>
106
107 - 单向模式:只增加不减少,初期就采用这种简单的模式
108 - 一些产品中成长值一直累积,伴随的会员等级一直成长,例如:QQ等级随着在线时间的增加而成长,从星星到月亮到太阳最后到皇冠,这种会员等级是单向的,永远朝着更高级别成长。这种规则下,成长值是无消耗的
109 - 双向模式:会根据规则增加和减少,也会影响对应的会员等级变化,一般适用于粘性较高,有一定用户基础的产品
110 - 一些产品充成长值是双向的,根据规则可增加可减少,对应的会员等级也会动态的变化
111 - 典型的例如王者荣耀的段位排名机制
112 - 还有在电商体系中
113 - 用户获得成长值的行为失效需要扣减对应成长值,例如:退货、删除评价等行为
114 - 后台人工干预扣除成长值等
115 - 一些平台也会在一个特定的时间周期评估用户的各种数据,根据规则重新计算出成长值,然后得出会员等级
116
117 ##### <font color='forestgreen'>成长值与会员等级</font>
118
119 成长值与会员等级有确定的对应关系,当成长值累计到一定数值时,会员等级会随之提升
120
121 ##### <font color='forestgreen'>会员等级</font>
122
123 尊享会员、钻石会员...(产品侧定义)
124
125 ##### <font color='forestgreen'>会员vip标识</font>
126
127 - 不同付费档次(OMO)
128 - 非会员
129 - 团粉(关注)
130 - 上电视会员(99元购买)
131 - 小演员普通版(999元购买)
132 - 小演员黄金版(5999元购买)
133
134 ##### <font color='forestgreen'>会员等级/vip权益</font>
135
136 - <font color='red'>一次性奖励权益</font>
137 - 达到对应等级所能获得的奖励,可以是积分、优惠券、其他实体
138 - 采用任务-权益体系实现
139 - <font color='red'>解锁特权</font>
140 - 下单折扣
141 - 包邮
142 - 免费观影
143 - 积分加成
144 - 。。。
145
146 ##### <font color='forestgreen'>成长值风控(第一阶段不做)</font>
147
148 - 成长值上限
149 - 在设置成长值来源时可针对每个来源设置每日获取上限值,同样也可针对每个账号设置每日获取上限值,超过上限时完成任务不再增加成长值
150 - 异常数据报警
151 - 通过系统监控所有会员的成长值增加&消耗情况,例如某个会员的成长值突然在短时间内剧增,增幅已经达到系统预警,则需要对该会员的具体数据&行为进行分析
152 - 黑白名单
153 - 黑名单无法获得成长值
154 - 白名单特殊待遇
155 - 人工干预
156 - 针对部分系统无法自动处理的场景,可在开发时预留成长值更改接口,运营人员可在后台手动扣减/奖励用户的成长值
157
158 ##### <font color='forestgreen'>成长值明细/历史</font>
159
160 详见成长值/积分计算引擎章节
161
162
163
164 #### 积分体系
165
166 > 积分体系和会员成长体系最基本的模型是一样的,只不过从简单到复杂的演变的过程中表现出了不同的特点。积分可以抽象地理解为现实生活中的货币,货币有发行和回收机制,积分同样也有<font color='red'>发行和回收机制</font>,不然都会导致通货膨胀
167
168 ![image-20210927141420693](https://cy-topdraw.oss-cn-shanghai.aliyuncs.com/typora/20210927141420.png)
169
170 ##### <font color='forestgreen'>积分价值</font>
171
172 - 虚拟货币,需要预先调研定义其货币价值
173 - 通过成本管控,防止通货膨胀和营销亏损
174
175 ##### <font color='forestgreen'>积分获取/风控</font>
176
177 - 同成长值获取,不在赘述
178
179 ##### <font color='forestgreen'>积分消耗</font>
180
181 - 积分商城
182 - 使用商城服务,消耗积分获得商品
183 - 抵扣购物
184 - 属于积分商场的一种特殊情况,允许用户在购买某一件商品时,使用积分+货币的方式进行组合支付
185 - 兑换活动机会
186 - 虚拟物品的一种,也可以是某一张观影券,用户通过这些虚拟物品,可以得到享受到相关的服务
187
188 ##### <font color='forestgreen'>跨屏积分(一般指大小屏)</font>
189
190 - 积分合并
191 - 策略A:小屏为主体,合并操作后大屏积分划为小屏积分(第一阶段以此策略为主)
192 - 策略B:所有绑定大屏的小屏,共享使用小屏积分
193 - 多屏积分的价值比例
194
195 ##### <font color='forestgreen'>积分到期</font>
196
197 - 积分有效期,定期清理,清理时机为查询积分或使用积分时
198 - 即将到期积分,为用户每次登陆时计算一次
199
200 ##### <font color='forestgreen'>积分使用优先级</font>
201
202 - 优先使用即将到期积分
203
204 ##### <font color='forestgreen'>积分历史</font>
205
206 - 积分获取
207 - 途径
208 - 时间
209 - 业务线
210 - 积分消耗
211 - 途径
212 - 时间
213 - 业务线
214
215 ##### <font color='forestgreen'>系统台账</font>
216
217 - 系统级别的整体积分清单
218
219
220
221 #### 权益体系
222
223 > 权益体系定义了用户在整个会员系统中能获得的权益集合,包含多种不同的权益类型,用户通过完成任务获得对应的权益
224
225 ##### <font color='forestgreen'>权益种类</font>
226
227 ###### <font color='dodgerblue'>核心类</font>
228
229 - 成长值
230 - 积分
231
232 ###### <font color='dodgerblue'>其他类</font>
233
234 - 优惠券
235 - 观影券
236 - 活动参与机会
237 - 。。。
238
239 ##### <font color='forestgreen'>权益的失效类型</font>
240
241 - 指定时间范围(每日清空也算是一种特殊的指定时间范围)
242 - 获取权益后若干时间后
243
244 ##### <font color='forestgreen'>权益实体</font>
245
246 之前在活动模块设计方案中,权益相关模型没有建立,只是使用权益类型和权益数量来描述权益的获得信息。<font color='red'>针对会员系统的营销多元化手段,将成长值、积分两大常规权益单独独立出来,其余类型权益统一建立权益实体来维护</font>
247
248 权益实体可对应优惠券、观影券、奖品、活动参与机会(对应活动),采用entity_type和entity_id的常规模式来描述
249
250 ##### <font color='forestgreen'>权益的发放</font>
251
252 ###### <font color='dodgerblue'>即时发放</font>
253
254 - 积分、成长值等通过会员引擎计算,即时发放
255 - 会员等级一次性权益发放
256 - 大多任务的权益为此类型
257
258 ###### <font color='dodgerblue'>定期发放</font>
259
260 - 会员vip/会员等级的月度权益,以月为时间单位发放
261
262 ###### <font color='dodgerblue'>即时获取</font>
263
264 - 会员权带来的活动次数增加
265 - 在参与活动时额外地为他增加一次活动机会
266
267
268
269 #### 任务体系
270
271 > 所有的权益获得都通过完成任务这一统一概念获得,任务体系作为一个基础能力贯穿会员系统的始终。<font color='red'>任务定义了不同种类、不同数量、不同组合的用户操作所能获得权益的规则</font>
272
273 ##### <font color='forestgreen'>关注事件</font>
274
275 - 任务的关注事件和消息生产者的topic相关
276 - 登录任务关注登录事件
277 - 观影类任务关注用户播放事件
278
279 ##### <font color='forestgreen'>对应权益</font>
280
281 - 完成任务可以获得对应的权益
282 - 成长值、积分属于特殊权益,有别于其他类型权益单独配置
283 - 一个任务的完成,可配置可获得成长值、可获得积分、可获得其他类型权益(唯一)
284 - 权益需要配置,指定一个确定的权益,如果只有积分或成长值的权益奖励,那无需配置具体其他类型权益
285
286 ##### <font color='forestgreen'>任务类型</font>
287
288 - 单次
289 - 每日
290 - 非每日
291 - 多次(有上线)
292 - 每日
293 - 非每日
294 - 无限次
295
296 ##### <font color='forestgreen'>任务进度</font>
297
298 - 对于需要重复完成的操作才能满足条件的任务,进度表可做相关记录
299 - <font color='red'>已完成的行为量/目标行为量=任务完成进度</font>
300 - 可支持累计观看、累计登录送XXX等业务
301 - 随着更多业务场景的引入和复杂度的提升,后续可能需要task detail表支持,验证任务进度的变化
302
303
304
305 ### <font color='darkblue'>User Center管理侧功能</font>
306
307 #### 会员管理
308
309 ##### <font color='forestgreen'>会员查询</font>
310
311 - 基本属性
312 - 地址属性(不同选项卡)
313 - 标签(来自于用户画像系统)
314 - 积分信息
315 - 当前积分,近期过期的积分
316 - 历史明细
317 - 黑名单管理
318
319 ##### <font color='forestgreen'>分群管理</font>
320
321 - 引用用户画像相关功能
322
323 ##### <font color='forestgreen'>会员等级管理</font>
324
325 - 名称、标识、状态、对应成长值、<font color='red'>对应权益</font>
326 - 权益会走任务条线
327 - 数据以顺序排列
328
329 ##### <font color='forestgreen'>成长任务管理</font>
330
331 - 任务的定义
332 - 关注事件
333 - 成长值的获得
334
335 #### 积分管理
336
337 ##### <font color='forestgreen'>积分查询</font>
338
339 - 按会员等级、地区、用户(可选)查询积分
340 - 查看指定用户积分详细
341 - 手工积分发放
342 - 也需要写明细
343 - 导出
344
345 ##### <font color='forestgreen'>积分任务管理</font>
346
347 - 任务的定义
348 - 关注事件
349 - 积分的获得
350
351 ##### <font color='forestgreen'>积分台账</font>
352
353 - 以日周月的维度展示系统整体积分变化
354 - 可查询特定时间整体积分的变化
355
356 #### 权益管理
357
358 ##### <font color='forestgreen'>权益定义</font>
359
360 - 名称、种类、失效类型。。。
361 - 对应实体类型
362
363 ##### <font color='forestgreen'>权益发放</font>
364
365 > 不通任务驱动,直接手工发放
366
367 - 对应权益,指定用户,进行发放,权益发放记录(表)
368
369 ##### <font color='forestgreen'>权益获取记录</font>
370
371 - 查询,见模型
372
373
374
375 ### <font color='darkblue'>User Center相关模型定义</font>
376
377 ![image-20210927191840834](https://cy-topdraw.oss-cn-shanghai.aliyuncs.com/typora/20210927191840.png)
378
379 #### 账号
380
381 - uc_user_tv为大屏表
382 - 在服务系统中,该表只会有一个渠道的记录
383 - 在管理系统中,该表会汇聚所有会员系统对接的渠道对应的大屏账号数据
384 - 小屏侧由于业务的差异性,根据具体客户端进行模型的分离
385
386 ##### <font color='forestgreen'>uc_user_tv 大屏账号</font>
387
388 ```sql
389 # 大屏账号表
390 CREATE TABLE `uc_user_tv` (
391 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
392 `member_id` bigint(20) DEFAULT NULL COMMENT '会员ID',
393 `platform` varchar(32) DEFAULT NULL COMMENT '运营商平台',
394 `platform_account` varchar(32) DEFAULT NULL COMMENT '运营商平台账号',
395 `cellphone` varchar(32) DEFAULT NULL COMMENT '手机号',
396 `username` varchar(32) DEFAULT NULL COMMENT '用户名',
397 `password` varchar(32) DEFAULT NULL COMMENT '密码 MD5',
398 `nickname` varchar(32) DEFAULT NULL COMMENT '昵称 Base64',
399 `image` varchar(1024) DEFAULT NULL COMMENT '头像',
400 `login_days` int(11) DEFAULT '0' COMMENT '登录天数(总天数)',
401 `continue_days` int(11) DEFAULT '0' COMMENT '连续登录天数',
402 `active_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '活跃时间',
403 `groups` varchar(32) DEFAULT NULL COMMENT '分组 分组ID用逗号分隔',
404 `tags` varchar(512) DEFAULT NULL COMMENT '标签 标签用逗号分隔',
405 `login_type` int(11) DEFAULT NULL COMMENT '登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录',
406 `status` int(11) DEFAULT NULL COMMENT '状态 0-下线 1-上线',
407 `description` varchar(512) DEFAULT NULL COMMENT '描述',
408 `create_by` varchar(32) DEFAULT 'system' COMMENT '创建者',
409 `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
410 `update_by` varchar(32) DEFAULT 'system' COMMENT '更新者',
411 `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
412 PRIMARY KEY (`id`),
413 KEY `member_id` (`member_id`),
414 KEY `platform` (`platform`),
415 KEY `platform_account` (`platform_account`),
416 KEY `username` (`username`),
417 KEY `status` (`status`)
418 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COMMENT='大屏账号表';
419 ```
420
421 ##### <font color='forestgreen'>uc_user_weixin微信账号</font>
422
423 ```sql
424 # 微信账号表
425 CREATE TABLE `uc_user_weixin` (
426 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
427 `member_id` bigint(20) DEFAULT NULL COMMENT '用户ID',
428 `unionid` varchar(32) DEFAULT NULL COMMENT '微信unionid,针对开发者',
429 `appid` varchar(32) DEFAULT NULL COMMENT '微信appid',
430 `openid` varchar(32) DEFAULT NULL COMMENT '微信openid,针对微信app',
431 `status` tinyint(4) DEFAULT '0' COMMENT '关注状态 0 -未关注 1 - 已关注',
432 `sync_status` tinyint(4) DEFAULT '0' COMMENT '关注同步状态 0-未同步,1-已同步',
433 `nickname` varchar(32) DEFAULT NULL COMMENT '昵称 base64',
434 `headimg_url` varchar(1024) DEFAULT NULL COMMENT '头像地址',
435 `privilege` varchar(32) DEFAULT NULL COMMENT '特权信息',
436 `refresh_token` varchar(128) DEFAULT NULL COMMENT '刷新凭据',
437 `access_token` varchar(128) DEFAULT NULL COMMENT '凭据',
438 `expires_in` int(11) DEFAULT NULL COMMENT '超时(秒)',
439 `expires_time` datetime DEFAULT NULL COMMENT '超时时间',
440 `description` varchar(512) DEFAULT NULL COMMENT '描述',
441 `create_by` varchar(32) DEFAULT 'system' COMMENT '创建者',
442 `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
443 `update_by` varchar(32) DEFAULT 'system' COMMENT '更新者',
444 `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
445 PRIMARY KEY (`id`),
446 KEY `member_id` (`member_id`),
447 KEY `unionid` (`unionid`)
448 ) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8 COMMENT='微信账号表';
449 ```
450
451
452
453 #### 用户/会员
454
455 ##### <font color='forestgreen'>uc_member_level 会员等级</font>
456
457 ```sql
458 # 会员等级表
459 CREATE TABLE `uc_member_level` (
460 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
461 `code` varchar(32) NOT NULL COMMENT '标识',
462 `name` varchar(255) NOT NULL COMMENT '名称',
463 `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:未启用;1:启用',
464 `exp_value` bigint(255) NOT NULL COMMENT '对应成长值',
465 `level` tinyint(4) NOT NULL DEFAULT '1' COMMENT '等级(不可重复,数字越大等级越高)',
466 `icon_url` varchar(255) DEFAULT NULL COMMENT '会员徽标',
467 `description` varchar(1024) DEFAULT NULL COMMENT '描述',
468 `task_id` bigint(20) DEFAULT NULL COMMENT '对应任务id,通过此字段可获得该等级所对应的权益',
469 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
470 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
471 PRIMARY KEY (`id`)
472 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员等级表';
473 ```
474
475 ##### <font color='forestgreen'>uc_member</font>
476
477 ```sql
478 # 会员表
479 CREATE TABLE `uc_member` (
480 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
481 `code` varchar(255) NOT NULL COMMENT '标识',
482 `type` tinyint(4) NOT NULL COMMENT '类型 1:大屏;2:小屏',
483 `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 0:不可用;(禁用权益)1:可用',
484 `nickname` varchar(64) DEFAULT NULL COMMENT '昵称 base64',
485 `description` varchar(1024) DEFAULT NULL COMMENT '描述',
486 `gender` tinyint(4) NOT NULL DEFAULT '-1' COMMENT '性别 0:女;1:男;-1:未知',
487 `birthday` varchar(32) DEFAULT NULL COMMENT '生日',
488 `avatar_url` varchar(1024) DEFAULT NULL COMMENT '头像',
489 `groups` varchar(255) DEFAULT NULL COMMENT '分组信息',
490 `tags` varchar(1024) DEFAULT NULL COMMENT '标签',
491 `vip` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:非会员;1:xx会员; 2:xx会员;(数据字典配置)',
492 `level` tinyint(4) NOT NULL DEFAULT '1' COMMENT '会员等级(对应level表的level字段,非id)',
493 `exp` bigint(20) DEFAULT NULL COMMENT '成长值',
494 `points` bigint(20) DEFAULT NULL COMMENT '当前积分',
495 `due_points` bigint(20) DEFAULT NULL COMMENT '即将到期积分(一个月内)',
496 `coupon_amount` int(11) DEFAULT NULL COMMENT '优惠券数量',
497 `due_coupon_amount` int(11) DEFAULT NULL COMMENT '即将过期优惠券数量',
498 `user_iptv_id` bigint(20) DEFAULT NULL COMMENT 'iptv账号id',
499 `bind_iptv_platform_type` tinyint(4) DEFAULT NULL COMMENT '绑定IPTV平台 0:未知;1:电信;2:移动;3:联通',
500 `bind_iptv_time` datetime DEFAULT NULL COMMENT 'iptv账号',
501 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
502 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
503 PRIMARY KEY (`id`),
504 KEY `code` (`code`),
505 KEY `nickname` (`nickname`)
506 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员表';
507 ```
508
509 ##### <font color='forestgreen'>uc_member_profile 会员基础信息</font>
510
511 ```sql
512 # 会员基础信息表
513 CREATE TABLE `uc_member_profile` (
514 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
515 `member_id` bigint(20) NOT NULL COMMENT '会员id',
516 `realname` varchar(32) DEFAULT NULL COMMENT '姓名',
517 `gender` tinyint(4) NOT NULL DEFAULT '-1' COMMENT '性别 0:女; 1:男 -1:未知',
518 `birthday` date NOT NULL DEFAULT '1900-01-01' COMMENT '生日',
519 `constellation` varchar(32) DEFAULT NULL COMMENT '星座',
520 `id_card` varchar(32) NOT NULL DEFAULT '000000000000000000' COMMENT '身份证',
521 `email` varchar(64) DEFAULT NULL COMMENT '电子邮件',
522 `country` varchar(32) DEFAULT NULL COMMENT '国家',
523 `province` varchar(32) DEFAULT NULL COMMENT '省份',
524 `city` varchar(32) DEFAULT NULL COMMENT '城市',
525 `district` varchar(32) DEFAULT NULL COMMENT '区县',
526 `description` varchar(1024) DEFAULT NULL COMMENT '描述',
527 `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
528 `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
529 PRIMARY KEY (`id`),
530 KEY `member_id` (`member_id`)
531 ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='会员基础信息表';
532 ```
533
534 ##### <font color='forestgreen'>uc_member_address 会员地址信息</font>
535
536 ```sql
537 # 会员地址信息表
538 CREATE TABLE `uc_member_address` (
539 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
540 `member_id` bigint(20) NOT NULL COMMENT '会员id',
541 `type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '类型 1:家;2:公司;3:学校',
542 `is_default` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否默认地址',
543 `sequence` int(11) DEFAULT NULL COMMENT '显示顺序',
544 `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 0:不可用;1-可用',
545 `contactor` varchar(64) NOT NULL COMMENT '联系人姓名',
546 `cellphone` varchar(32) NOT NULL COMMENT '联系人电话',
547 `country` varchar(64) NOT NULL COMMENT '国家',
548 `province` varchar(64) NOT NULL COMMENT '省份',
549 `city` varchar(64) NOT NULL COMMENT '城市',
550 `district` varchar(64) NOT NULL COMMENT '区县',
551 `address` varchar(255) NOT NULL COMMENT '地址',
552 `zip_code` varchar(16) DEFAULT NULL COMMENT '邮编',
553 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
554 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
555 PRIMARY KEY (`id`),
556 KEY `member_id` (`member_id`),
557 KEY `contactor` (`contactor`),
558 KEY `cellphone` (`cellphone`)
559 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员地址信息表';
560 ```
561
562 ##### <font color='forestgreen'>uc_member_related_info 会员相关人信息</font>
563
564 ```sql
565 # 会员相关人信息表
566 CREATE TABLE `uc_member_related_info` (
567 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
568 `member_id` bigint(20) NOT NULL COMMENT '会员id',
569 `type` tinyint(4) DEFAULT NULL COMMENT '人物关系 0:子女;1:父母',
570 `cellphone` varchar(32) DEFAULT NULL COMMENT '手机号',
571 `id_card` varchar(32) DEFAULT NULL COMMENT '身份证号',
572 `name` varchar(32) DEFAULT NULL COMMENT '姓名',
573 `sex` tinyint(4) DEFAULT NULL COMMENT '性别 0:女;1:男;-1:未知',
574 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
575 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
576 PRIMARY KEY (`id`)
577 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员相关人信息表';
578 ```
579
580 ##### <font color='forestgreen'>uc_permanent_rights 永久权益</font>
581
582 ```sql
583 # 永久权益表
584 CREATE TABLE `uc_permanent_rights` (
585 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
586 `code` varchar(64) NOT NULL COMMENT '标识',
587 `name` varchar(255) NOT NULL COMMENT '名称',
588 `type` tinyint(4) DEFAULT NULL COMMENT '永久权益类型 0:vip;1:会员等级',
589 `level` tinyint(4) DEFAULT NULL COMMENT '等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index)',
590 `item_discount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商品折扣,10代表10% off,范围为0-100',
591 `extra_points` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '额外积分比率,范围为0-1000',
592 `ad_disabled` tinyint(4) NOT NULL DEFAULT '0' COMMENT '免广告',
593 `extra_activity_ticket` tinyint(4) NOT NULL DEFAULT '0' COMMENT '额外活动参与机会',
594 `free_trial` tinyint(4) NOT NULL DEFAULT '0' COMMENT '免费试看',
595 `zone_sds` tinyint(4) NOT NULL DEFAULT '0' COMMENT '上电视专区权益',
596 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
597 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
598 PRIMARY KEY (`id`)
599 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='永久权益表';
600 ```
601
602
603
604 #### 任务/权益
605
606 > 抽象统一的任务/权益模型,覆盖成长值任务、积分任务及其他任务
607
608 ##### <font color='forestgreen'>tr_rights 权益</font>
609
610 ```sql
611 # 权益表
612 CREATE TABLE `tr_rights` (
613 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
614 `code` varchar(64) NOT NULL COMMENT '标识',
615 `type` tinyint(4) NOT NULL COMMENT '类型 1:实体类 (预留字段)',
616 `device_type` tinyint(4) DEFAULT NULL COMMENT '终端类型 0:大屏;1:微信小程序/公众号;2:App',
617 `entity_type` varchar(64) NOT NULL COMMENT '权益的实体类型',
618 `entity_id` bigint(20) NOT NULL COMMENT '实体id',
619 `image` varchar(1024) DEFAULT NULL COMMENT '图片',
620 `images` varchar(1024) DEFAULT NULL COMMENT '图片',
621 `description` varchar(1024) DEFAULT NULL COMMENT '描述',
622 `valid_time` datetime DEFAULT NULL COMMENT '生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间',
623 `expire_time` bigint(20) DEFAULT NULL COMMENT '失效时间,空为不失效,否则为获得权益后直到失效的毫秒数',
624 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
625 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
626 PRIMARY KEY (`id`),
627 KEY `entity_type` (`entity_type`),
628 KEY `entity_id` (`entity_id`)
629 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权益表';
630 ```
631
632 ##### <font color='forestgreen'>tr_task_template 任务模板</font>
633
634 ```sql
635 # 任务模板表
636 CREATE TABLE `tr_task_template` (
637 `id` bigint(20) NOT NULL AUTO_INCREMENT,
638 `code` varchar(64) DEFAULT NULL COMMENT '标识',
639 `name` varchar(255) DEFAULT NULL COMMENT '名称',
640 `event` varchar(255) DEFAULT NULL COMMENT '关注事件(和MQ topic相关)',
641 `description` varchar(1020) COMMENT '描述',
642 `status` tinyint(4) DEFAULT 1 COMMENT '状态 0:失效;1:生效',
643 `type` tinyint(4) DEFAULT 0 COMMENT '类型 0:活动任务模板',
644 `params` text DEFAULT NULL COMMENT '模板参数,json',
645 `create_time` datetime DEFAULT NULL,
646 `update_time` datetime DEFAULT NULL,
647 PRIMARY KEY (`id`) USING BTREE
648 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='任务模板表';
649 ```
650
651 ##### <font color='forestgreen'>tr_task 任务</font>
652
653 ```sql
654 CREATE TABLE `tr_task` (
655 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
656 `code` varchar(255) NOT NULL COMMENT '标识',
657 `name` varchar(255) NOT NULL COMMENT '名称',
658 `task_template_id` bigint(20) NOT NULL COMMENT '任务模板id',
659 `task_repeat_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '任务重复类型,-1:不限次;1:单次;>1:多次',
660 `task_daily_reset` tinyint(4) NOT NULL DEFAULT '0' COMMENT '任务每日重置 0:不重置;1:重置',
661 `action_amount` int(11) NOT NULL DEFAULT '1' COMMENT '行为量(完成此任务需要多少次相同行为的触发)',
662 `valid_time` datetime DEFAULT NULL COMMENT '任务生效时间',
663 `expire_time` datetime DEFAULT NULL COMMENT '任务失效时间',
664 `sequence` int(11) DEFAULT NULL COMMENT '显示顺序',
665 `reward_exp` bigint(20) NOT NULL DEFAULT '0' COMMENT '获得成长值',
666 `reward_points` bigint(20) NOT NULL DEFAULT '0' COMMENT '获得积分(当积分获得类型为随机时,代表最小获得积分数)',
667 `reward_points_expire_time` bigint(20) DEFAULT NULL COMMENT '积分过期时间(空为不过期)',
668 `points_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '积分获取类型 0:定值;1:随机',
669 `reward_max_points` bigint(4) DEFAULT NULL COMMENT '随机积分最大值',
670 `groups` varchar(255) DEFAULT NULL COMMENT '能够获取该任务的用户分组,为空则都能获取',
671 `rights_send_strategy` tinyint(4) NOT NULL DEFAULT '0' COMMENT '权益发放策略 0:立即发放;1:次日发放;2:次月发放',
672 `member_exclusive` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员专享 0:非会员专享 1:会员专享',
673 `member_level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员等级门槛(0表示无门槛)',
674 `member_vip` tinyint(4) DEFAULT NULL COMMENT '会员vip门槛(0表示没有门槛)',
675 `rights_id` bigint(20) DEFAULT NULL COMMENT '权益id',
676 `rights_amount` int(11) DEFAULT NULL COMMENT '权益数量(活动机会次数、优惠券数量、奖品数量)',
677 `rights2_id` bigint(20) DEFAULT NULL COMMENT '权益2id',
678 `rights2_amount` int(11) DEFAULT NULL COMMENT '权益2数量',
679 `rights3_id` bigint(20) DEFAULT NULL COMMENT '权益3id',
680 `rights3_amount` int(255) DEFAULT NULL COMMENT '权益3数量',
681 `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 0:失效;1:生效',
682 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
683 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
684 PRIMARY KEY (`id`) USING BTREE,
685 KEY `rights_id` (`rights_id`)
686 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='任务表';
687 ```
688
689 ##### <font color='forestgreen'>tr_rights_history 权益发放记录</font>
690
691 ```sql
692 # 权益发放记录表
693 CREATE TABLE `tr_rights_histroy` (
694 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
695 `rights_id` bigint(20) DEFAULT NULL COMMENT '权益id',
696 `member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
697 `operator_id` bigint(20) DEFAULT NULL COMMENT '操作者id(手动发放时保存)',
698 `operator_name` varchar(255) DEFAULT NULL COMMENT '操作者名称(手动发放时保存)',
699 `send_time` datetime DEFAULT NULL COMMENT '发放时间',
700 `expire_time` datetime DEFAULT NULL COMMENT '失效时间',
701 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
702 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
703 PRIMARY KEY (`id`)
704 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权益发放记录';
705 ```
706
707
708
709 #### 成长值
710
711 ##### <font color='forestgreen'>uc_exp_detail 成长值历史</font>
712
713 ```sql
714 # 成长值明细表
715 CREATE TABLE `uc_exp_detail` (
716 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
717 `code` varchar(255) NOT NULL COMMENT '标识',
718 `app_code` varchar(64) DEFAULT NULL COMMENT '应用code',
719 `member_id` bigint(20) NOT NULL COMMENT '会员id',
720 `account_id` bigint(20) DEFAULT NULL COMMENT '账号id',
721 `original_exp` bigint(20) NOT NULL COMMENT '原始成长值',
722 `result_exp` bigint(20) NOT NULL COMMENT '结果成长值',
723 `exp` bigint(20) NOT NULL COMMENT '成长值变化,一般为正数',
724 `device_type` tinyint(4) NOT NULL COMMENT '设备类型 1:大屏;2:小屏(微信)3.小屏(xx)',
725 `evt_type` tinyint(4) NOT NULL DEFAULT '99' COMMENT '行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他',
726 `order_id` bigint(20) DEFAULT '0' COMMENT '订单id(针对订购操作)',
727 `media_id` bigint(20) DEFAULT '0' COMMENT '节目id(针对观影操作)',
728 `activity_id` bigint(20) DEFAULT NULL COMMENT '活动id(针对参与活动)',
729 `description` varchar(255) NOT NULL COMMENT '成长值变化描述,用于管理侧显示',
730 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
731 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
732 PRIMARY KEY (`id`),
733 KEY `member_id` (`member_id`),
734 KEY `evt_type` (`evt_type`)
735 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='成长值明细表';
736 ```
737
738 ##### <font color='forestgreen'>uc_exp_detail_history 成长值明细历史</font>
739
740 ```sql
741 # 成长值明细历史表
742 CREATE TABLE `uc_exp_history` (
743 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
744 `code` varchar(255) NOT NULL COMMENT '标识',
745 `app_code` varchar(64) DEFAULT NULL COMMENT '应用code',
746 `member_id` bigint(20) NOT NULL COMMENT '会员id',
747 `account_id` bigint(20) DEFAULT NULL COMMENT '账号id',
748 `original_exp` bigint(20) NOT NULL COMMENT '原始成长值',
749 `result_exp` bigint(20) NOT NULL COMMENT '结果成长值',
750 `exp` bigint(20) NOT NULL COMMENT '成长值变化,一般为正数',
751 `device_type` tinyint(4) NOT NULL COMMENT '设备类型 1:大屏;2:小屏(微信)3.小屏(xx)',
752 `evt_type` tinyint(4) NOT NULL DEFAULT '99' COMMENT '行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他',
753 `order_id` bigint(20) DEFAULT '0' COMMENT '订单id(针对订购操作)',
754 `media_id` bigint(20) DEFAULT '0' COMMENT '节目id(针对观影操作)',
755 `activity_id` bigint(20) DEFAULT NULL COMMENT '活动id(针对参与活动)',
756 `description` varchar(255) NOT NULL COMMENT '成长值变化描述,用于管理侧显示',
757 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
758 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
759 PRIMARY KEY (`id`),
760 KEY `member_id` (`member_id`),
761 KEY `evt_type` (`evt_type`)
762 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='成长值明细历史表';
763 ```
764
765
766
767 #### 积分
768
769 ##### <font color='forestgreen'>uc_points_detail 积分明细</font>
770
771 ```sql
772 # 积分历史表
773 CREATE TABLE `uc_points_detail` (
774 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
775 `code` varchar(64) NOT NULL COMMENT '标识',
776 `app_code` varchar(64) DEFAULT NULL COMMENT '应用code',
777 `member_id` bigint(20) NOT NULL COMMENT '会员id',
778 `account_id` bigint(20) DEFAULT NULL COMMENT '账号id',
779 `original_points` bigint(20) NOT NULL COMMENT '原始积分',
780 `result_points` bigint(20) NOT NULL COMMENT '结果积分',
781 `points` bigint(20) NOT NULL COMMENT '积分变化,积分获得为正,积分消耗为负',
782 `device_type` tinyint(4) NOT NULL COMMENT '设备类型 1:大屏;2:小屏(微信)3.小屏(xx)',
783 `evt_type` tinyint(4) NOT NULL DEFAULT '99' COMMENT '行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他',
784 `order_id` bigint(20) DEFAULT '0' COMMENT '订单id(针对订购操作)',
785 `media_id` bigint(20) DEFAULT '0' COMMENT '节目id(针对观影操作)',
786 `activity_id` bigint(20) DEFAULT NULL COMMENT '活动id(针对参与活动)',
787 `item_id` bigint(20) DEFAULT NULL COMMENT '商品id(积分兑换,同时写入订单id)',
788 `description` varchar(255) NOT NULL COMMENT '积分变化描述,用于管理侧显示',
789 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
790 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
791 PRIMARY KEY (`id`),
792 KEY `member_id` (`member_id`),
793 KEY `evt_type` (`evt_type`)
794 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='积分明细表';
795 ```
796
797 ##### <font color='forestgreen'>uc_points_detail_history 积分明细历史</font>
798
799 ```sql
800 # 积分历史表
801 CREATE TABLE `uc_points_detail_history` (
802 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
803 `code` varchar(64) NOT NULL COMMENT '标识',
804 `app_code` varchar(64) DEFAULT NULL COMMENT '应用code',
805 `member_id` bigint(20) NOT NULL COMMENT '会员id',
806 `account_id` bigint(20) DEFAULT NULL COMMENT '账号id',
807 `original_points` bigint(20) NOT NULL COMMENT '原始积分',
808 `result_points` bigint(20) NOT NULL COMMENT '结果积分',
809 `points` bigint(20) NOT NULL COMMENT '积分变化,积分获得为正,积分消耗为负',
810 `device_type` tinyint(4) NOT NULL COMMENT '设备类型 1:大屏;2:小屏(微信)3.小屏(xx)',
811 `evt_type` tinyint(4) NOT NULL DEFAULT '99' COMMENT '行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他',
812 `order_id` bigint(20) DEFAULT '0' COMMENT '订单id(针对订购操作)',
813 `media_id` bigint(20) DEFAULT '0' COMMENT '节目id(针对观影操作)',
814 `activity_id` bigint(20) DEFAULT NULL COMMENT '活动id(针对参与活动)',
815 `description` varchar(255) NOT NULL COMMENT '积分变化描述,用于管理侧显示',
816 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
817 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
818 PRIMARY KEY (`id`),
819 KEY `member_id` (`member_id`),
820 KEY `evt_type` (`evt_type`)
821 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='积分明细历史表';
822 ```
823
824 ##### <font color='forestgreen'>uc_points_available 可用积分表</font>
825
826 ```sql
827 # 可用积分表
828 CREATE TABLE `uc_points_available` (
829 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
830 `code` varchar(64) NOT NULL COMMENT '标识',
831 `points_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '积分类型 0:通用型',
832 `device_type` tinyint(4) DEFAULT NULL COMMENT '设备类型 1:大屏;2:小屏(微信)3.小屏(xx)',
833 `member_id` bigint(20) NOT NULL COMMENT '会员id',
834 `points` bigint(20) NOT NULL COMMENT '积分值',
835 `expire_time` datetime DEFAULT NULL COMMENT '过期时间',
836 `description` varchar(255) NOT NULL COMMENT '描述',
837 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
838 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
839 PRIMARY KEY (`id`),
840 KEY `member_id` (`member_id`)
841 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='可用积分表';
842 ```
843
844 ##### <font color='forestgreen'>uc_points_standing_book 积分台账</font>
845
846 ```sql
847 # 积分台账表
848 CREATE TABLE `uc_points_standing_book` (
849 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
850 `points_produce` bigint(20) NOT NULL COMMENT '积分生产',
851 `points_consume` bigint(20) NOT NULL COMMENT '积分消耗',
852 `points_available` bigint(20) NOT NULL COMMENT '可用总积分',
853 `points_expire` bigint(20) NOT NULL COMMENT '积分过期',
854 `day` varchar(16) DEFAULT NULL COMMENT '日期',
855 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
856 `update_time` datetime DEFAULT NULL COMMENT '创建时间',
857 PRIMARY KEY (`id`)
858 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分台账表';
859 ```
860
861
862
863 #### 优惠券
864
865 > 使用商城系统中的营销模块,基本没有改变
866
867 ##### <font color='forestgreen'>m_coupon 优惠券</font>
868
869 ```sql
870 #优惠券表
871 CREATE TABLE `m_coupon` (
872 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
873 `code` varchar(64) NOT NULL COMMENT '标识',
874 `title` varchar(255) NOT NULL COMMENT '名称',
875 `images` varchar(1024) DEFAULT NULL COMMENT '图片',
876 `stock` int(11) DEFAULT '-1' COMMENT '发行量,-1代表不限量',
877 `remain_stock` int(11) DEFAULT '-1' NULL COMMENT '剩余量,-1代表不限量',
878 `use_type` tinyint(4) DEFAULT '1' COMMENT '优惠形式:1:金额;2:折扣',
879 `denomination` decimal(10,2) DEFAULT NULL COMMENT '面额',
880 `discount` decimal(10,2) DEFAULT NULL COMMENT '折扣',
881 `user_range` tinyint(4) DEFAULT '2' COMMENT '适用用户范围:1:新用户;2:全体用户;3:指定用户分组',
882 `groups` varchar(1024) DEFAULT NULL COMMENT '用户分组,逗号分隔',
883 `collect_limit` tinyint(4) DEFAULT '1' COMMENT '限领次数 -1:无限次; >0:具体次数',
884 `threshold_type` tinyint(4) DEFAULT '1' COMMENT '适用门槛:1:无门槛;2:满减形式',
885 `amount_threshold` decimal(10,2) DEFAULT null COMMENT '满减门槛',
886 `item_range` tinyint(4) DEFAULT '1' COMMENT '产品范围:1:全部商品;2:指定商品',
887 `effect_type` tinyint(4) DEFAULT null COMMENT '生效形式:1:固定日期;2:相对日期',
888 `start_time` datetime DEFAULT NULL COMMENT '生效时间',
889 `expire_time` datetime DEFAULT NULL COMMENT '过期时间',
890 `valid_days` int(11) DEFAULT NULL COMMENT '自领取当日,几天内有效',
891 `description` varchar(255) DEFAULT NULL COMMENT '使用说明',
892 `status` tinyint(4) DEFAULT null COMMENT '状态 0:未开始,1:启用;2:停用',
893 `member_exclusive` tinyint(4) DEFAULT null COMMENT '会员专享 0:非会员专享 1:会员专享',
894 `member_level` tinyint(4) DEFAULT null COMMENT '会员等级门槛(0:表示无门槛)',
895 `member_vip` tinyint(4) DEFAULT null COMMENT '会员vi门槛(0:表示无门槛)',
896 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
897 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
898 PRIMARY KEY (`id`)
899 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=' 优惠券表';
900 ```
901
902 ##### <font color='forestgreen'>m_coupon_history</font>
903
904 ```sql
905 #优惠券领取、使用历史记录表
906 CREATE TABLE `m_coupon_history` (
907 `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
908 `coupon_id` bigint DEFAULT NULL COMMENT '优惠券id',
909 `user_id` bigint DEFAULT NULL COMMENT '领券用户id(对应账号)',
910 `coupon_code` varchar(64) DEFAULT NULL COMMENT '优惠券code',
911 `user_nickname` varchar(255) DEFAULT NULL COMMENT '领取人昵称',
912 `receive_time` datetime DEFAULT NULL COMMENT '领取时间',
913 `expire_time` datetime DEFAULT NULL COMMENT '失效时间',
914 `use_status` int DEFAULT NULL COMMENT '使用状态 0:未使用;1:已使用;-1:已过期',
915 `use_time` datetime DEFAULT NULL COMMENT '使用时间',
916 `order_detail_id` bigint DEFAULT NULL COMMENT '订单详情id',
917 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
918 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
919 PRIMARY KEY (`id`),
920 KEY `idx_member_id` (`user_id`) USING BTREE,
921 KEY `idx_coupon_id` (`coupon_id`)
922 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券领取、使用历史记录表';
923 ```
924
925
926
927 ### <font color='darkblue'>User Center 成长值/积分计算引擎,API</font>
928
929 > 会员成长/积分计算引擎内置于User Center中,<font color='red'>负责异步处理成长值、积分的获得,一般为消息队列的消费者</font>,通过不同的事件进行驱动,数据库指向服务侧
930
931 > 会员引擎统一API数据库指向管理侧,<font color='red'>在中央统一处理积分的消耗,避免多端的数据一致性问题</font>,具体部署时应考虑系统压力
932
933 简单来说,积分的获得实时性要求不高,由服务侧通过消息队列,异步更新到中央数据库中,积分的消耗由于牵涉到并发,数据一致性问题,直接请求api,中央统一处理保证数据的一致性
934
935 #### 引擎功能
936
937 ![image-20210927153528449](https://cy-topdraw.oss-cn-shanghai.aliyuncs.com/typora/20210927153528.png)
938
939 #### 会员引擎架构
940
941 ![image-20210927181349132](https://cy-topdraw.oss-cn-shanghai.aliyuncs.com/typora/20210927181349.png)
942
943
944
945 #### 积分过期、积分消耗、积分明细查询的技术实现
946
947 积分明细表记录了用户积分的增减情况,需要展现给用户,所以无法在这上面下手,为此新添加了一张表来记录当前<font color='red'>可用积分明细</font>。该表的关键字段如下:
948
949 | 字段 | 含义 |
950 | -------- | ---------------- |
951 | 积分值 | 该记录的积分值 |
952 | 创建时间 | 该积分的生效时间 |
953 | 过期时间 | 该积分的过期时间 |
954
955 ##### <font color='forestgreen'>积分过期</font>
956
957 - <font color='red'>可用积分表</font>(uc_points_available)删除过期记录
958 - <font color='red'>积分明细表</font>(uc_points_detail)添加一条过期明细,即负的积分
959 - <font color='red'>积分总额表</font>(uc_points)更新为当前积分总额
960
961 > 每天定时扫描<font color='red'>可用积分表</font>,将过期积分删除,并及时更新积分明细表和积分总额表
962
963 ##### <font color='forestgreen'>积分使用</font>
964
965 ![image-20210927155637989](https://cy-topdraw.oss-cn-shanghai.aliyuncs.com/typora/20210927155638.png)
966
967
968
969
970
971
972
973
974
975 ### <font color='darkblue'>商城服务体系</font>
976
977 #### 商品体系
978
979 > 商品整个设计见mall-service相关文档
980
981 - 支持商品会员价
982 - vip/会员等级权益(折扣)
983 - 会员专属价格(不建议等级差异化,过于复杂)
984 - 上述两者最好二选一,或者有会员专属价格的优先计算,不再使用vip/会员等级权益折扣
985 - 支持会员专享商品
986 - 角标
987 - <font color='red'>下单接口一定要区分领券购买和普通购买</font>
988
989 #### 营销体系
990
991 #### 模型变更
992
993 ##### <font color='forestgreen'>i_item 商品</font>
994
995 ```sql
996 # 会员专享
997 ALTER TABLE i_item ADD COLUMN member_exclusive tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员专享 0:非会员专享 1:会员专享' AFTER is_unite_tail;
998 ALTER TABLE i_item ADD COLUMN member_price decimal(10,2) NOT NULL COMMENT '会员价格' AFTER price;
999 ```
1000
1001 ##### <font color='forestgreen'>i_sku 商品规格</font>
1002
1003 ```sql
1004 # 会员价
1005 ALTER TABLE i_sku ADD COLUMN member_price decimal(10,2) DEFAULT NULL COMMENT '会员价格' AFTER promotion_price;
1006 ```
1007
1008 ##### <font color='forestgreen'>m_coupon</font>
1009
1010 ```sql
1011 # 会员专享
1012 ALTER TABLE `m_coupon` ADD COLUMN `member_exclusive` tinyint(4) NULL DEFAULT 0 COMMENT '会员专享 0:非会员专享 1:会员专享' AFTER `effect_type`;
1013 # 会员等级门槛
1014 ALTER TABLE `m_coupon` ADD COLUMN `member_level` tinyint(4) NULL DEFAULT 0 COMMENT '会员等级门槛(0表示无门槛)' AFTER `member_exclusive`;
1015 # 会员vip门槛
1016 ALTER TABLE `m_coupon` ADD COLUMN `member_vip` tinyint(4) NULL DEFAULT 0 COMMENT '会员vip门槛(0表示没有门槛)' AFTER `member_level`;
1017 ```
1018
1019
1020
1021 ### <font color='darkblue'>活动服务体系</font>
1022
1023 >为了区分IPTV常规营销活动和小屏侧主题活动(暂定名)或赛事,<font color='red'>将原有的活动模型拆分为两个独立的模型,明晰模型定位</font>
1024
1025 #### 营销活动
1026
1027 常规的IPTV影响活动,现在主要分为三大类,投票、抽奖、闯关。后续可根据实际情况扩展。
1028
1029 此部分有单独文档定义,这里不再赘述。
1030
1031 #### 主题活动
1032
1033 - OMO新版本的核心
1034 - 支持报名相关配置
1035 - 活动的参与条件
1036 - 流程的完整定义(报名、参与、审核、支付、证书)
1037
1038 ##### <font color='forestgreen'>ugc</font>
1039
1040 - ugc是主题活动关联的主体,不再关联原先的营销活动
1041 - ugc支持作品、花絮不同种类的支持
1042 - ugc的投票已支持
1043 - ugc的点赞
1044 - ugc的评论(短期不做)
1045 - 动态???
1046
1047 ##### <font color='forestgreen'>报名</font>
1048
1049 - 报名费统一采用商品支持,即主题活动可关联商品(开启报名为前提)
1050 - 活动邀请券使用商品优惠券的方式实现
1051 - 全额抵扣
1052 - 部分抵扣
1053 - 优惠券受会员等级约束
1054
1055 ##### <font color='forestgreen'>商品包装</font>
1056
1057 > 主题活动可作为商品的一种包装形式,<font color='red'>可支持特殊商品的定制化呈现</font>
1058
1059 - 普通商品的包装
1060 - 报名费的包装
1061
1062
1063
1064 #### 主题活动专区
1065
1066 - OMO新版本需求核心“小演员”,“上电视”其实就是专区的概念
1067 - 专区类似栏目,支持对主题活动的编排
1068
1069
1070
1071 #### 模型定义
1072
1073 ##### <font color='forestgreen'>act_theme_activity_section 主题活动专区</font>
1074
1075 ```sql
1076 # 主题活动专区表
1077 CREATE TABLE `act_theme_activity_section` (
1078 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
1079 `code` varchar(32) NOT NULL COMMENT '标识',
1080 `name` varchar(255) NOT NULL COMMENT '名称',
1081 `description` varchar(1000) DEFAULT NULL COMMENT '描述',
1082 `sequence` int(11) NOT NULL DEFAULT '0' COMMENT '显示顺序',
1083 `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 0:下线;1:上线',
1084 `member_exclusive` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员专享 0:非会员专享 1:会员专享',
1085 `member_level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员等级门槛(0表示没有门槛)',
1086 `member_vip` tinyint(4) DEFAULT NULL COMMENT '会员vip门槛(0表示没有门槛)',
1087 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
1088 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
1089 PRIMARY KEY (`id`)
1090 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='主题活动专区表';
1091 ```
1092
1093 ##### <font color='forestgreen'>act_theme_activity 主题活动</font>
1094
1095 ```sql
1096 # 主题活动表
1097 CREATE TABLE `act_theme_activity` (
1098 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
1099 `code` varchar(32) NOT NULL COMMENT '标识',
1100 `name` varchar(255) NOT NULL COMMENT '名称',
1101 `description` varchar(1000) DEFAULT NULL COMMENT '描述',
1102 `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态 0:下线;1:上线',
1103 `sequence` int(11) NOT NULL DEFAULT '0' COMMENT '显示顺序',
1104 `section_id` bigint(20) NOT NULL COMMENT '专区id',
1105 `member_exclusive` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员专享 0:非会员专享 1:会员专享',
1106 `member_level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员等级门槛(0表示无门槛)',
1107 `member_vip` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员vip门槛(0表示没有门槛)',
1108 `app_id` bigint(20) NOT NULL COMMENT '所属应用',
1109 `start_time` datetime NOT NULL COMMENT '活动开始时间',
1110 `end_time` datetime NOT NULL COMMENT '活动结束时间',
1111 `register_switch` tinyint(4) NOT NULL DEFAULT '1' COMMENT '报名开关 0:关闭报名环节;1:开启报名环节',
1112 `register_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '报名类型 0:资质类;1:直通类',
1113 `register_info` varchar(1000) DEFAULT NULL COMMENT '报名信息(json格式)',
1114 `register_ugc_type` tinyint(4) DEFAULT NULL COMMENT '报名作品类型 0:图片;1:视频;10:图片或视频',
1115 `register_start_time` datetime DEFAULT NULL COMMENT '报名开始时间',
1116 `register_end_time` datetime DEFAULT NULL COMMENT '报名截止时间',
1117 `item_id` bigint(20) DEFAULT NULL COMMENT '商品id(主题活动/报名费可视作一个商品,只有在开启报名时有效)',
1118 `vote_activity_id` bigint(20) DEFAULT NULL COMMENT '投票活动id(当主题活动有投票环节时启用)',
1119 `group_range` varchar(500) DEFAULT NULL COMMENT '活动分组列表,多个使用逗号分隔',
1120 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
1121 `update_time` datetime DEFAULT NULL COMMENT '更新时间',
1122 PRIMARY KEY (`id`)
1123 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='主题活动表';
1124 ```
1125
1126 #### 模型变更
1127
1128 ##### <font color='forestgreen'>x_ugc</font>
1129
1130 ```sql
1131 # 会员id
1132 ALTER TABLE x_ugc ADD COLUMN member_id bigint(20) COMMENT '会员id' AFTER user_id;
1133 # ugc
1134 ALTER TABLE x_ugc ADD COLUMN category tinyint(4) COMMENT '类别 0:作品;1:花絮' AFTER type;
1135 # 审核原因
1136 ALTER TABLE `x_ugc` ADD COLUMN `audit_remark` varchar(2048) NULL COMMENT '审核原因' AFTER `comment_number`;
1137 ```
1138
1139 ##### <font color='forestgreen'>act_user_sign_up</font>
1140
1141 ```sql
1142 # 审核原因
1143 ALTER TABLE `act_user_sign_up` ADD COLUMN `audit_remark` varchar(2048) NULL COMMENT '审核原因' AFTER `qualification_image`;
1144 ```
1145
1146
1147
1148
1149
1150 ### <font color='darkblue'>CMS系统</font>
1151
1152 #### 推荐位编排
1153
1154 > 支持上电视专区的瀑布流配置
1155 >
1156
1157 - 支持主题活动跳转
1158 - 支持主题活动专区跳转
1159
1160
1161
1162 ### <font color='darkblue'>boss系统</font>
1163
1164
1165
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <parent>
6 <artifactId>member-service</artifactId>
7 <groupId>com.topdraw</groupId>
8 <version>0.0.1-SNAPSHOT</version>
9 </parent>
10 <modelVersion>4.0.0</modelVersion>
11
12 <artifactId>member-service-api</artifactId>
13
14 <properties>
15
16 </properties>
17
18 <dependencies>
19 <!--代码生成器-->
20 <dependency>
21 <groupId>com.topdraw</groupId>
22 <artifactId>code-generator</artifactId>
23 <version>3.1.0</version>
24 </dependency>
25 </dependencies>
26
27 </project>
...\ No newline at end of file ...\ No newline at end of file
1 package com.topdraw.module.mq;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
6
7 import javax.validation.constraints.NotNull;
8 import java.io.Serializable;
9
10 /**
11 *
12 */
13 @Data
14 @AllArgsConstructor
15 @NoArgsConstructor
16 public class DataSyncMsg implements Serializable {
17
18 // 事件类型(用户的实际操作)
19 @NotNull
20 private String eventType;
21
22 // 消息体
23 private MsgData msg;
24
25 // 其他属性
26 private String extraData;
27
28
29 /**
30 * 消息体
31 */
32 @Data
33 @AllArgsConstructor
34 @NoArgsConstructor
35 public static class MsgData {
36 private String remarks; //备注
37 @NotNull
38 private Integer event; // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
39 @NotNull
40 private Long memberId; // 会员id
41 @NotNull
42 private Integer deviceType; //设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
43 @NotNull
44 private String appCode; //用户对应的应用code
45 private Long accountId; // 账号id
46 private Long orderId;
47 private Long activityId;
48 private Long mediaId;
49 private Long itemId;
50 }
51
52 }
1 package com.topdraw.module.mq;
2
3 import lombok.Getter;
4
5 // 实体类型
6 @Getter
7 public enum EntityType {
8
9 // 用户
10 PERSON,
11 // 会员
12 MEMBER,
13 // 小屏-微信
14 WEIXIN_USER,
15 // 大屏
16 VIS_USER,
17 // 地址
18 PERSON_ADDRESS
19
20 }
1 package com.topdraw.module.mq;
2
3 // 关注的事件
4 public enum EventType {
5
6 // 关注
7 SUBSCRIBE,
8 // 取消关注
9 UN_SUBSCRIBE,
10 // 绑定
11 BIND,
12 // 取消绑定
13 UN_BIND,
14 // 变更主账号
15 C_M_ACCOUNT,
16 // 获取积分
17 GAIN_POINT,
18 // 消耗积分
19 CONSUME_POINT,
20 // 观影
21 VIEWING,
22 // 登录
23 LOGIN,
24 // 订购产品包
25 SUBSCRIBE_PRODUCT_PACKAGE
26
27
28 }
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <parent>
6 <artifactId>member-service</artifactId>
7 <groupId>com.topdraw</groupId>
8 <version>0.0.1-SNAPSHOT</version>
9 </parent>
10 <modelVersion>4.0.0</modelVersion>
11
12 <artifactId>member-service-impl</artifactId>
13
14 <properties>
15 <maven.compiler.source>8</maven.compiler.source>
16 <maven.compiler.target>8</maven.compiler.target>
17 <jjwt.version>0.9.1</jjwt.version>
18 </properties>
19
20
21 <dependencies>
22
23 <!--redisson-->
24 <dependency>
25 <groupId>org.redisson</groupId>
26 <artifactId>redisson</artifactId>
27 <version>3.16.3</version>
28 </dependency>
29
30 <!--api-->
31 <dependency>
32 <groupId>com.topdraw</groupId>
33 <artifactId>member-service-api</artifactId>
34 <version>${parent.version}</version>
35 </dependency>
36
37 <!--代码生成器-->
38 <dependency>
39 <groupId>com.topdraw</groupId>
40 <artifactId>code-generator</artifactId>
41 <version>3.1.0</version>
42 </dependency>
43
44 <!-- Spring boot 热部署 : 此热部署会遇到 java.lang.ClassCastException 异常 -->
45 <dependency>
46 <groupId>org.springframework.boot</groupId>
47 <artifactId>spring-boot-devtools</artifactId>
48 <optional>true</optional>
49 <scope>runtime</scope>
50 </dependency>
51
52 <dependency>
53 <groupId>org.springframework.boot</groupId>
54 <artifactId>spring-boot-starter-test</artifactId>
55 </dependency>
56
57 <!--Mysql依赖包,版本差异,需单独引入-->
58 <dependency>
59 <groupId>mysql</groupId>
60 <artifactId>mysql-connector-java</artifactId>
61 <version>8.0.26</version>
62 </dependency>
63
64 <dependency>
65 <groupId>junit</groupId>
66 <artifactId>junit</artifactId>
67 <version>4.12</version>
68 <scope>test</scope>
69 </dependency>
70
71 <!-- 支持AES/CBC/PKCS7Padding,用于微信小程序登录数据解密 -->
72 <dependency>
73 <groupId>org.bouncycastle</groupId>
74 <artifactId>bcprov-jdk16</artifactId>
75 <version>1.46</version>
76 </dependency>
77
78 <!--消息队列相关依赖-->
79 <dependency>
80 <groupId>org.springframework.boot</groupId>
81 <artifactId>spring-boot-starter-amqp</artifactId>
82 </dependency>
83
84 <!--重试-->
85 <dependency>
86 <groupId>org.springframework.retry</groupId>
87 <artifactId>spring-retry</artifactId>
88 </dependency>
89
90 <dependency>
91 <groupId>org.aspectj</groupId>
92 <artifactId>aspectjweaver</artifactId>
93 </dependency>
94
95 <dependency>
96 <groupId>commons-codec</groupId>
97 <artifactId>commons-codec</artifactId>
98 <version>1.9</version>
99 </dependency>
100
101 </dependencies>
102
103
104 <profiles>
105 <profile>
106 <!-- 本地开发环境 -->
107 <id>dev</id>
108 <properties>
109 <profiles.active>dev</profiles.active>
110 </properties>
111 <activation>
112 <!-- 默认的,不加参数时执行这个profile -->
113 <activeByDefault>true</activeByDefault>
114 </activation>
115 </profile>
116 <profile>
117 <!-- 生产环境 -->
118 <id>prod</id>
119 <properties>
120 <profiles.active>prod</profiles.active>
121 <modifier>-prod</modifier>
122 </properties>
123 </profile>
124 </profiles>
125
126 <build>
127 <finalName>member-service</finalName>
128 <plugins>
129 <plugin>
130 <groupId>org.springframework.boot</groupId>
131 <artifactId>spring-boot-maven-plugin</artifactId>
132 <configuration>
133 <fork>true</fork>
134 </configuration>
135 </plugin>
136 <!-- 跳过单元测试 -->
137 <plugin>
138 <groupId>org.apache.maven.plugins</groupId>
139 <artifactId>maven-surefire-plugin</artifactId>
140 <configuration>
141 <skipTests>true</skipTests>
142 </configuration>
143 </plugin>
144 <!-- 复制指定配置文件到指定目录 -->
145 <plugin>
146 <artifactId>maven-resources-plugin</artifactId>
147 <executions>
148 <execution>
149 <id>copy-resources</id>
150 <phase>package</phase>
151 <goals>
152 <goal>copy-resources</goal>
153 </goals>
154 <configuration>
155 <resources>
156 <resource>
157 <directory>src/main/resources/config</directory>
158 <includes>
159 <include>application.yml</include>
160 <include>application-${profiles.active}.yml</include>
161 </includes>
162 </resource>
163 </resources>
164 <outputDirectory>${project.build.directory}/config</outputDirectory>
165 </configuration>
166 </execution>
167 </executions>
168 </plugin>
169 <!-- jar包内剔除所有配置文件 -->
170 <plugin>
171 <artifactId>maven-jar-plugin</artifactId>
172 <configuration>
173 <!--不打入jar包的文件类型或者路径-->
174 <excludes>
175 <exclude>config/**</exclude>
176 </excludes>
177 </configuration>
178 </plugin>
179 </plugins>
180 </build>
181
182 </project>
...\ No newline at end of file ...\ No newline at end of file
1 package com.topdraw;
2
3 import com.topdraw.utils.SpringContextHolder;
4 import org.springframework.boot.SpringApplication;
5 import org.springframework.boot.autoconfigure.SpringBootApplication;
6 import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
7 import org.springframework.boot.builder.SpringApplicationBuilder;
8 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
11 import org.springframework.retry.annotation.EnableRetry;
12 import org.springframework.scheduling.annotation.EnableAsync;
13 import org.springframework.transaction.annotation.EnableTransactionManagement;
14
15 /**
16 * @author XiangHan
17 * @version 0.0.1
18 */
19 @EnableJpaAuditing
20 @EnableAsync
21 @SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
22 @EnableTransactionManagement
23 @EnableRetry
24 public class MemberServiceApplication extends SpringBootServletInitializer {
25
26 public static void main(String[] args) {
27 SpringApplication.run(MemberServiceApplication.class, args);
28 }
29
30 @Override
31 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
32 return builder.sources(MemberServiceApplication.class);
33 }
34
35 @Bean
36 public SpringContextHolder springContextHolder() {
37 return new SpringContextHolder();
38 }
39 }
1 package com.topdraw.aspect;
2
3
4 import com.alibaba.fastjson.JSON;
5 import com.topdraw.mq.domain.TableOperationMsg;
6 import com.topdraw.mq.producer.MessageProducer;
7 import lombok.extern.slf4j.Slf4j;
8 import org.aspectj.lang.JoinPoint;
9 import org.aspectj.lang.annotation.*;
10 import org.aspectj.lang.reflect.MethodSignature;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
15 import org.springframework.stereotype.Component;
16 import org.springframework.util.StringUtils;
17
18 import javax.annotation.Resource;
19 import java.lang.reflect.Method;
20
21 @Component
22 @Slf4j
23 @Aspect
24 public class AsyncMqProducer {
25
26 private static final Logger LOG = LoggerFactory.getLogger(AsyncMqProducer.class);
27
28 @Autowired
29 MessageProducer messageProducer;
30
31 @Resource(name = "executorTask")
32 ThreadPoolTaskExecutor threadPoolTaskExecutor;
33
34 @Pointcut(value = "@annotation(asyncMqSend)")
35 public void sendMqMsg(AsyncMqSend asyncMqSend){
36 LOG.info("AsyncMqProducer ===>>> sendMqMsg ====>> start");
37 }
38
39 @After("sendMqMsg(asyncMqSend)")
40 public void doAfter(JoinPoint joinPoint, AsyncMqSend asyncMqSend){
41 LOG.info("AsyncMqProducer ===>>> doAfter ====>> start");
42 boolean open = asyncMqSend.open();
43 if (open) {
44 try {
45 this.doTask(joinPoint,asyncMqSend);
46 } catch (Throwable e) {
47 e.printStackTrace();
48 }
49 }
50 LOG.info("AsyncMqProducer ===>>> doAfter ====>> end ===>> " );
51 }
52
53 private void doTask(JoinPoint joinPoint, AsyncMqSend asyncMqSend) {
54 LOG.info("AsyncMqProducer ===>>> doTask ====>> start ===>> " );
55
56 String entityName = asyncMqSend.entityName();
57 String methodName = asyncMqSend.method();
58
59 Object defaultServiceImpl = joinPoint.getTarget();
60 String defaultServiceImplName = defaultServiceImpl.getClass().getName();
61
62 MethodSignature signature = (MethodSignature)joinPoint.getSignature();
63 Method method = signature.getMethod();
64 String defaultMethodName = method.getName();
65
66 Object[] args = joinPoint.getArgs();
67 Object arg = args[0];
68 String defaultEntityName = arg.getClass().getName();
69
70 TableOperationMsg tableOperationMsg = new TableOperationMsg();
71 tableOperationMsg.setMethodName(StringUtils.isEmpty(methodName)?defaultMethodName:methodName);
72 tableOperationMsg.setEntityBody(JSON.toJSONString(arg));
73 tableOperationMsg.setInterfaceName(defaultServiceImplName);
74 tableOperationMsg.setEntityName(StringUtils.isEmpty(entityName)?defaultEntityName:entityName);
75
76 boolean async = asyncMqSend.async();
77 if (async) {
78 // 异步
79 this.sendMqMessage(tableOperationMsg);
80 } else {
81 // 同步
82 this.sendMqMessage(tableOperationMsg);
83 }
84
85 LOG.info("AsyncMqProducer ===>>> doTask ====>> end ===>> " );
86 }
87
88 private void sendMqMessage(TableOperationMsg tableOperationMsg){
89 this.messageProducer.sendFanoutMessage(JSON.toJSONString(tableOperationMsg));
90 }
91
92 }
1 package com.topdraw.aspect;
2
3 import org.springframework.amqp.core.ExchangeTypes;
4
5 import java.lang.annotation.*;
6
7 /**
8 * 在对应的方法上添加此注解,表示对应方法结束后
9 * 进行异步发送消息到mq中
10 *
11 * @author XiangHan
12 * @date 2021-10-30
13 */
14 @Documented
15 @Target({ElementType.METHOD})
16 @Retention(RetentionPolicy.RUNTIME)
17 public @interface AsyncMqSend {
18 /** true:开启 false:关闭 */
19 boolean open() default true;
20 /** true:异步 false:同步 */
21 boolean async() default true;
22 /** 接口实现 */
23 String serviceImpl() default "";
24 /** 对应的方法 */
25 String method() default "";
26 /** 实体名 */
27 String entityName() default "";
28 /** 交换机 */
29 String exchangeName() default "";
30 /** 队列名 */
31 String routeKeyName() default "";
32 /**交换机类型 */
33 String exchangeType() default ExchangeTypes.DIRECT;
34 }
1 package com.topdraw.business.basicdata.coupon.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12 import java.math.BigDecimal;
13
14 import java.io.Serializable;
15
16 /**
17 * @author XiangHan
18 * @date 2021-10-22
19 */
20 @Entity
21 @Data
22 @EntityListeners(AuditingEntityListener.class)
23 @Accessors(chain = true)
24 @Table(name="m_coupon")
25 public class Coupon implements Serializable {
26
27 // id
28 @Id
29 @GeneratedValue(strategy = GenerationType.IDENTITY)
30 @Column(name = "id")
31 private Long id;
32
33 // 标识
34 @Column(name = "code", nullable = false)
35 private String code;
36
37 // 名称
38 @Column(name = "title", nullable = false)
39 private String title;
40
41 // 图片
42 @Column(name = "images")
43 private String images;
44
45 // 发行量,-1代表不限量
46 @Column(name = "stock")
47 private Integer stock;
48
49 // 剩余量,-1代表不限量
50 @Column(name = "remain_stock")
51 private Integer remainStock;
52
53 // 优惠形式:1:现金;2:折扣
54 @Column(name = "use_type")
55 private Integer useType;
56
57 // 面额
58 @Column(name = "denomination")
59 private BigDecimal denomination;
60
61 // 折扣
62 @Column(name = "discount")
63 private BigDecimal discount;
64
65 // 适用用户范围:1:新用户;2:全体用户
66 @Column(name = "user_range")
67 private Integer userRange;
68
69 // 限领次数 -1:无限次; >0:具体次数
70 @Column(name = "collect_limit")
71 private Integer collectLimit;
72
73 // 适用门槛:1:无门槛;2:满减形式
74 @Column(name = "threshold_type")
75 private Integer thresholdType;
76
77 // 满减门槛
78 @Column(name = "amount_threshold")
79 private BigDecimal amountThreshold;
80
81 // 产品范围:1:全部商品;2:指定商品
82 @Column(name = "item_range")
83 private Integer itemRange;
84
85 // 生效形式:1:固定日期;2:相对日期
86 @Column(name = "effect_type")
87 private Integer effectType;
88
89 // 生效时间
90 @Column(name = "start_time")
91 private Timestamp startTime;
92
93 // 过期时间
94 @Column(name = "expire_time")
95 private Timestamp expireTime;
96
97 // 自领取当日,几天内有效
98 @Column(name = "valid_days")
99 private Integer validDays;
100
101 // 使用说明
102 @Column(name = "description")
103 private String description;
104
105 // 状态0:未开始,1:启用;2:停用
106 @Column(name = "status")
107 private Integer status;
108
109 // 创建时间
110 @CreatedDate
111 @Column(name = "create_time")
112 private Timestamp createTime;
113
114 // 更新时间
115 @LastModifiedDate
116 @Column(name = "update_time")
117 private Timestamp updateTime;
118
119 public void copy(Coupon source){
120 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
121 }
122 }
1 package com.topdraw.business.basicdata.coupon.history.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-23
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="m_coupon_history")
24 public class CouponHistory implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 优惠券id
33 @Column(name = "coupon_id")
34 private Long couponId;
35
36 // 领券用户id(对应账号)
37 @Column(name = "user_id")
38 private Long userId;
39
40 // 优惠券code
41 @Column(name = "coupon_code")
42 private String couponCode;
43
44 // 领取人昵称
45 @Column(name = "user_nickname")
46 private String userNickname;
47
48 // 领取时间
49 @Column(name = "receive_time")
50 private Timestamp receiveTime;
51
52 // 失效时间
53 @Column(name = "expire_time")
54 private Timestamp expireTime;
55
56 // 使用状态 0:未使用;1:已使用;-1:已过期
57 @Column(name = "use_status")
58 private Integer useStatus;
59
60 // 使用时间
61 @Column(name = "use_time")
62 private Timestamp useTime;
63
64 // 订单详情id
65 @Column(name = "order_detail_id")
66 private Long orderDetailId;
67
68 // 创建时间
69 @CreatedDate
70 @Column(name = "create_time")
71 private Timestamp createTime;
72
73 // 更新时间
74 @LastModifiedDate
75 @Column(name = "update_time")
76 private Timestamp updateTime;
77
78 public void copy(CouponHistory source){
79 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
80 }
81 }
1 package com.topdraw.business.basicdata.coupon.history.repository;
2
3 import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.sql.Timestamp;
8 import java.util.Optional;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-23
13 */
14 public interface CouponHistoryRepository extends JpaRepository<CouponHistory, Long>, JpaSpecificationExecutor<CouponHistory> {
15
16 Long countByUserId(Long userId);
17
18 Long countByUserIdAndExpireTimeBefore(Long userId, Timestamp now);
19
20 Long countByUserIdAndExpireTimeBetween(Long userId, Timestamp now, Timestamp expireTime);
21 }
1 package com.topdraw.business.basicdata.coupon.history.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory;
6 import com.topdraw.business.basicdata.coupon.history.service.CouponHistoryService;
7 import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.http.HttpStatus;
11 import org.springframework.http.ResponseEntity;
12 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.*;
14 import io.swagger.annotations.*;
15 import java.io.IOException;
16 import javax.servlet.http.HttpServletResponse;
17
18 /**
19 * @author XiangHan
20 * @date 2021-10-23
21 */
22 @Api(tags = "CouponHistory管理")
23 @RestController
24 @RequestMapping("/api/CouponHistory")
25 public class CouponHistoryController {
26
27 @Autowired
28 private CouponHistoryService CouponHistoryService;
29
30 @GetMapping
31 @ApiOperation("查询CouponHistory")
32 public ResultInfo getCouponHistorys(CouponHistoryQueryCriteria criteria, Pageable pageable) {
33 return ResultInfo.successPage(CouponHistoryService.queryAll(criteria,pageable));
34 }
35
36 @GetMapping(value = "/all")
37 @ApiOperation("查询所有CouponHistory")
38 public ResultInfo getCouponHistorys(CouponHistoryQueryCriteria criteria) {
39 return ResultInfo.success(CouponHistoryService.queryAll(criteria));
40 }
41
42 @Log
43 @PostMapping
44 @ApiOperation("新增CouponHistory")
45 public ResultInfo create(@Validated @RequestBody CouponHistory resources) {
46 CouponHistoryService.create(resources);
47 return ResultInfo.success();
48 }
49
50 @Log
51 @PutMapping
52 @ApiOperation("修改CouponHistory")
53 public ResultInfo update(@Validated @RequestBody CouponHistory resources) {
54 CouponHistoryService.update(resources);
55 return ResultInfo.success();
56 }
57
58
59 @Log
60 @DeleteMapping(value = "/{id}")
61 @ApiOperation("删除CouponHistory")
62 public ResultInfo delete(@PathVariable Long id) {
63 CouponHistoryService.delete(id);
64 return ResultInfo.success();
65 }
66
67 }
1 package com.topdraw.business.basicdata.coupon.history.service;
2
3 import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory;
4 import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryDTO;
5 import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7
8 import java.sql.Timestamp;
9 import java.util.Map;
10 import java.util.List;
11 import java.io.IOException;
12 import javax.servlet.http.HttpServletResponse;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-23
17 */
18 public interface CouponHistoryService {
19
20 /**
21 * 查询数据分页
22 * @param criteria 条件参数
23 * @param pageable 分页参数
24 * @return Map<String,Object>
25 */
26 Map<String,Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable);
27
28 /**
29 * 查询所有数据不分页
30 * @param criteria 条件参数
31 * @return List<CouponHistoryDTO>
32 */
33 List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria);
34
35 /**
36 * 根据ID查询
37 * @param id ID
38 * @return CouponHistoryDTO
39 */
40 CouponHistoryDTO findById(Long id);
41
42 void create(CouponHistory resources);
43
44 void update(CouponHistory resources);
45
46 void delete(Long id);
47
48 Long countByUserId(Long userId);
49
50 Long countByUserIdAndExpireTimeBefore(Long userId, Timestamp now);
51
52 Long countByUserIdAndExpireTimeBetween(Long userId, Timestamp now, Timestamp expireTime);
53 }
1 package com.topdraw.business.basicdata.coupon.history.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-23
11 */
12 @Data
13 public class CouponHistoryDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 优惠券id
19 private Long couponId;
20
21 // 领券用户id(对应账号)
22 private Long userId;
23
24 // 优惠券code
25 private String couponCode;
26
27 // 领取人昵称
28 private String userNickname;
29
30 // 领取时间
31 private Timestamp receiveTime;
32
33 // 失效时间
34 private Timestamp expireTime;
35
36 // 使用状态 0:未使用;1:已使用;-1:已过期
37 private Integer useStatus;
38
39 // 使用时间
40 private Timestamp useTime;
41
42 // 订单详情id
43 private Long orderDetailId;
44
45 // 创建时间
46 private Timestamp createTime;
47
48 // 更新时间
49 private Timestamp updateTime;
50 }
1 package com.topdraw.business.basicdata.coupon.history.service.dto;
2
3 import lombok.Data;
4 import com.topdraw.annotation.Query;
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-23
9 */
10 @Data
11 public class CouponHistoryQueryCriteria{
12 }
1 package com.topdraw.business.basicdata.coupon.history.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.coupon.history.repository.CouponHistoryRepository;
7 import com.topdraw.business.basicdata.coupon.history.service.CouponHistoryService;
8 import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryDTO;
9 import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryQueryCriteria;
10 import com.topdraw.business.basicdata.coupon.history.service.mapper.CouponHistoryMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21
22 import java.sql.Timestamp;
23 import java.util.List;
24 import java.util.Map;
25
26 /**
27 * @author XiangHan
28 * @date 2021-10-23
29 */
30 @Service
31 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
32 public class CouponHistoryServiceImpl implements CouponHistoryService {
33
34 @Autowired
35 private CouponHistoryRepository CouponHistoryRepository;
36
37 @Autowired
38 private CouponHistoryMapper CouponHistoryMapper;
39
40 @Override
41 public Map<String, Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable) {
42 Page<CouponHistory> page = CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
43 return PageUtil.toPage(page.map(CouponHistoryMapper::toDto));
44 }
45
46 @Override
47 public List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria) {
48 return CouponHistoryMapper.toDto(CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
49 }
50
51 @Override
52 public CouponHistoryDTO findById(Long id) {
53 CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseGet(CouponHistory::new);
54 ValidationUtil.isNull(CouponHistory.getId(),"CouponHistory","id",id);
55 return CouponHistoryMapper.toDto(CouponHistory);
56 }
57
58 @Override
59 @Transactional(rollbackFor = Exception.class)
60 @AsyncMqSend()
61 public void create(CouponHistory resources) {
62 CouponHistoryRepository.save(resources);
63 }
64
65 @Override
66 @Transactional(rollbackFor = Exception.class)
67 @AsyncMqSend()
68 public void update(CouponHistory resources) {
69 CouponHistory CouponHistory = CouponHistoryRepository.findById(resources.getId()).orElseGet(CouponHistory::new);
70 ValidationUtil.isNull( CouponHistory.getId(),"CouponHistory","id",resources.getId());
71 CouponHistory.copy(resources);
72 CouponHistoryRepository.save(CouponHistory);
73 }
74
75 @Override
76 @Transactional(rollbackFor = Exception.class)
77 public void delete(Long id) {
78 Assert.notNull(id, "The given id must not be null!");
79 CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseThrow(
80 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", CouponHistory.class, id), 1));
81 CouponHistoryRepository.delete(CouponHistory);
82 }
83
84 @Override
85 public Long countByUserId(Long userId) {
86 return this.CouponHistoryRepository.countByUserId(userId);
87 }
88
89 @Override
90 public Long countByUserIdAndExpireTimeBefore(Long userId, Timestamp now) {
91 return this.CouponHistoryRepository.countByUserIdAndExpireTimeBefore(userId,now);
92 }
93
94 @Override
95 public Long countByUserIdAndExpireTimeBetween(Long userId, Timestamp now, Timestamp expireTime) {
96 return this.CouponHistoryRepository.countByUserIdAndExpireTimeBetween(userId,now,expireTime);
97 }
98
99
100 }
1 package com.topdraw.business.basicdata.coupon.history.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory;
5 import com.topdraw.business.basicdata.coupon.history.service.dto.CouponHistoryDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-23
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface CouponHistoryMapper extends BaseMapper<CouponHistoryDTO, CouponHistory> {
15
16 }
1 package com.topdraw.business.basicdata.coupon.repository;
2
3 import com.topdraw.business.basicdata.coupon.domain.Coupon;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface CouponRepository extends JpaRepository<Coupon, Long>, JpaSpecificationExecutor<Coupon> {
14
15 Optional<Coupon> findFirstByCode(String code);
16 }
1 package com.topdraw.business.basicdata.coupon.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.coupon.domain.Coupon;
6 import com.topdraw.business.basicdata.coupon.service.CouponService;
7 import com.topdraw.business.basicdata.coupon.service.dto.CouponQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "Coupon管理")
19 @RestController
20 @RequestMapping("/api/Coupon")
21 public class CouponController {
22
23 @Autowired
24 private CouponService CouponService;
25
26 @GetMapping
27 @ApiOperation("查询Coupon")
28 public ResultInfo getCoupons(CouponQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(CouponService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有Coupon")
34 public ResultInfo getCoupons(CouponQueryCriteria criteria) {
35 return ResultInfo.success(CouponService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增Coupon")
41 public ResultInfo create(@Validated @RequestBody Coupon resources) {
42 CouponService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改Coupon")
49 public ResultInfo update(@Validated @RequestBody Coupon resources) {
50 CouponService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除Coupon")
58 public ResultInfo delete(@PathVariable Long id) {
59 CouponService.delete(id);
60 return ResultInfo.success();
61 }
62
63 @GetMapping(value = "/getByCode/{code}")
64 @ApiOperation(value = "根据标识查询")
65 public ResultInfo getByCode(@PathVariable String code) {
66 return ResultInfo.success(CouponService.getByCode(code));
67 }
68 }
1 package com.topdraw.business.basicdata.coupon.service;
2
3 import com.topdraw.business.basicdata.coupon.domain.Coupon;
4 import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO;
5 import com.topdraw.business.basicdata.coupon.service.dto.CouponQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface CouponService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(CouponQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<CouponDTO>
28 */
29 List<CouponDTO> queryAll(CouponQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return CouponDTO
35 */
36 CouponDTO findById(Long id);
37
38 void create(Coupon resources);
39
40 void update(Coupon resources);
41
42 void delete(Long id);
43
44 /**
45 * Code校验
46 * @param code
47 * @return CouponDTO
48 */
49 CouponDTO getByCode(String code);
50 }
1 package com.topdraw.business.basicdata.coupon.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.math.BigDecimal;
6 import java.io.Serializable;
7
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Data
14 public class CouponDTO implements Serializable {
15
16 // id
17 private Long id;
18
19 // 标识
20 private String code;
21
22 // 名称
23 private String title;
24
25 // 图片
26 private String images;
27
28 // 发行量,-1代表不限量
29 private Integer stock;
30
31 // 剩余量,-1代表不限量
32 private Integer remainStock;
33
34 // 优惠形式:1:现金;2:折扣
35 private Integer useType;
36
37 // 面额
38 private BigDecimal denomination;
39
40 // 折扣
41 private BigDecimal discount;
42
43 // 适用用户范围:1:新用户;2:全体用户
44 private Integer userRange;
45
46 // 限领次数 -1:无限次; >0:具体次数
47 private Integer collectLimit;
48
49 // 适用门槛:1:无门槛;2:满减形式
50 private Integer thresholdType;
51
52 // 满减门槛
53 private BigDecimal amountThreshold;
54
55 // 产品范围:1:全部商品;2:指定商品
56 private Integer itemRange;
57
58 // 生效形式:1:固定日期;2:相对日期
59 private Integer effectType;
60
61 // 生效时间
62 private Timestamp startTime;
63
64 // 过期时间
65 private Timestamp expireTime;
66
67 // 自领取当日,几天内有效
68 private Integer validDays;
69
70 // 使用说明
71 private String description;
72
73 // 状态0:未开始,1:启用;2:停用
74 private Integer status;
75
76 // 创建时间
77 private Timestamp createTime;
78
79 // 更新时间
80 private Timestamp updateTime;
81 }
1 package com.topdraw.business.basicdata.coupon.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class CouponQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.coupon.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.coupon.domain.Coupon;
5 import com.topdraw.util.RedissonUtil;
6 import com.topdraw.utils.ValidationUtil;
7 import com.topdraw.business.basicdata.coupon.repository.CouponRepository;
8 import com.topdraw.business.basicdata.coupon.service.CouponService;
9 import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO;
10 import com.topdraw.business.basicdata.coupon.service.dto.CouponQueryCriteria;
11 import com.topdraw.business.basicdata.coupon.service.mapper.CouponMapper;
12 import org.redisson.api.RLock;
13 import org.redisson.api.RedissonClient;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Service;
16 import org.springframework.transaction.annotation.Propagation;
17 import org.springframework.transaction.annotation.Transactional;
18 import org.springframework.dao.EmptyResultDataAccessException;
19 import org.springframework.data.domain.Page;
20 import org.springframework.data.domain.Pageable;
21 import org.springframework.util.Assert;
22 import com.topdraw.utils.PageUtil;
23 import com.topdraw.utils.QueryHelp;
24 import com.topdraw.utils.StringUtils;
25
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30 * @author XiangHan
31 * @date 2021-10-22
32 */
33 @Service
34 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
35 public class CouponServiceImpl implements CouponService {
36
37 @Autowired
38 private CouponRepository CouponRepository;
39
40 @Autowired
41 private CouponMapper CouponMapper;
42
43 @Autowired
44 private RedissonClient redissonClient;
45
46 @Override
47 public Map<String, Object> queryAll(CouponQueryCriteria criteria, Pageable pageable) {
48 Page<Coupon> page = CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
49 return PageUtil.toPage(page.map(CouponMapper::toDto));
50 }
51
52 @Override
53 public List<CouponDTO> queryAll(CouponQueryCriteria criteria) {
54 return CouponMapper.toDto(CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
55 }
56
57 @Override
58 public CouponDTO findById(Long id) {
59 Coupon Coupon = CouponRepository.findById(id).orElseGet(Coupon::new);
60 ValidationUtil.isNull(Coupon.getId(),"Coupon","id",id);
61 return CouponMapper.toDto(Coupon);
62 }
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 @AsyncMqSend()
67 public void create(Coupon resources) {
68 CouponRepository.save(resources);
69 }
70
71 @Override
72 @Transactional(rollbackFor = Exception.class)
73 @AsyncMqSend()
74 public void update(Coupon resources) {
75 RLock rLock = this.redissonClient.getLock(resources.getId().toString());
76 try {
77 RedissonUtil.lock(rLock);
78 Coupon Coupon = CouponRepository.findById(resources.getId()).orElseGet(Coupon::new);
79 ValidationUtil.isNull( Coupon.getId(),"Coupon","id",resources.getId());
80 Coupon.copy(resources);
81 CouponRepository.save(Coupon);
82 } catch (Exception e) {
83 e.printStackTrace();
84 throw e;
85 } finally {
86 RedissonUtil.unlock(rLock);
87 }
88 }
89
90 @Override
91 @Transactional(rollbackFor = Exception.class)
92 @AsyncMqSend()
93 public void delete(Long id) {
94 Assert.notNull(id, "The given id must not be null!");
95 Coupon Coupon = CouponRepository.findById(id).orElseThrow(
96 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Coupon.class, id), 1));
97 CouponRepository.delete(Coupon);
98 }
99
100
101 @Override
102 public CouponDTO getByCode(String code) {
103 return StringUtils.isNotEmpty(code) ? CouponMapper.toDto(CouponRepository.findFirstByCode(code).orElseGet(Coupon::new))
104 : new CouponDTO();
105 }
106 }
1 package com.topdraw.business.basicdata.coupon.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.coupon.domain.Coupon;
5 import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface CouponMapper extends BaseMapper<CouponDTO, Coupon> {
15
16 }
1 package com.topdraw.business.basicdata.exp.detail.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_exp_detail")
24 public class ExpDetail implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 标识
33 @Column(name = "code", nullable = false)
34 private String code;
35
36 // 应用code
37 @Column(name = "app_code")
38 private String appCode;
39
40 // 会员id
41 @Column(name = "member_id", nullable = false)
42 private Long memberId;
43
44 // 账号id
45 @Column(name = "account_id")
46 private Long accountId;
47
48 // 原始成长值
49 @Column(name = "original_exp", nullable = false)
50 private Long originalExp;
51
52 // 结果成长值
53 @Column(name = "result_exp", nullable = false)
54 private Long resultExp;
55
56 // 成长值变化,一般为正数
57 @Column(name = "exp", nullable = false)
58 private Long exp;
59
60 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
61 @Column(name = "device_type", nullable = false)
62 private Integer deviceType;
63
64 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他
65 @Column(name = "evt_type", nullable = false)
66 private Integer evtType;
67
68 // 订单id(针对订购操作)
69 @Column(name = "order_id")
70 private Long orderId;
71
72 // 节目id(针对观影操作)
73 @Column(name = "media_id")
74 private Long mediaId;
75
76 // 活动id(针对参与活动)
77 @Column(name = "activity_id")
78 private Long activityId;
79
80 // 成长值变化描述,用于管理侧显示
81 @Column(name = "description", nullable = false)
82 private String description;
83
84 // 创建时间
85 @CreatedDate
86 @Column(name = "create_time")
87 private Timestamp createTime;
88
89 // 更新时间
90 @LastModifiedDate
91 @Column(name = "update_time")
92 private Timestamp updateTime;
93
94 public void copy(ExpDetail source){
95 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
96 }
97 }
1 package com.topdraw.business.basicdata.exp.detail.repository;
2
3 import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface ExpDetailRepository extends JpaRepository<ExpDetail, Long>, JpaSpecificationExecutor<ExpDetail> {
14
15 Optional<ExpDetail> findFirstByCode(String code);
16 }
1 package com.topdraw.business.basicdata.exp.detail.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail;
6 import com.topdraw.business.basicdata.exp.detail.service.ExpDetailService;
7 import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "ExpDetail管理")
19 @RestController
20 @RequestMapping("/api/ExpDetail")
21 public class ExpDetailController {
22
23 @Autowired
24 private ExpDetailService ExpDetailService;
25
26 @GetMapping
27 @ApiOperation("查询ExpDetail")
28 public ResultInfo getExpDetails(ExpDetailQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(ExpDetailService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有ExpDetail")
34 public ResultInfo getExpDetails(ExpDetailQueryCriteria criteria) {
35 return ResultInfo.success(ExpDetailService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增ExpDetail")
41 public ResultInfo create(@Validated @RequestBody ExpDetail resources) {
42 ExpDetailService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改ExpDetail")
49 public ResultInfo update(@Validated @RequestBody ExpDetail resources) {
50 ExpDetailService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除ExpDetail")
58 public ResultInfo delete(@PathVariable Long id) {
59 ExpDetailService.delete(id);
60 return ResultInfo.success();
61 }
62
63 @GetMapping(value = "/getByCode/{code}")
64 @ApiOperation(value = "根据标识查询")
65 public ResultInfo getByCode(@PathVariable String code) {
66 return ResultInfo.success(ExpDetailService.getByCode(code));
67 }
68 }
1 package com.topdraw.business.basicdata.exp.detail.service;
2
3 import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail;
4 import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailDTO;
5 import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface ExpDetailService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<ExpDetailDTO>
28 */
29 List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return ExpDetailDTO
35 */
36 ExpDetailDTO findById(Long id);
37
38 void create(ExpDetail resources);
39
40 void update(ExpDetail resources);
41
42 void delete(Long id);
43
44 /**
45 * Code校验
46 * @param code
47 * @return ExpDetailDTO
48 */
49 ExpDetailDTO getByCode(String code);
50 }
1 package com.topdraw.business.basicdata.exp.detail.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class ExpDetailDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 应用code
22 private String appCode;
23
24 // 会员id
25 private Long memberId;
26
27 // 账号id
28 private Long accountId;
29
30 // 原始成长值
31 private Long originalExp;
32
33 // 结果成长值
34 private Long resultExp;
35
36 // 成长值变化,一般为正数
37 private Long exp;
38
39 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
40 private Integer deviceType;
41
42 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他
43 private Integer evtType;
44
45 // 订单id(针对订购操作)
46 private Long orderId;
47
48 // 节目id(针对观影操作)
49 private Long mediaId;
50
51 // 活动id(针对参与活动)
52 private Long activityId;
53
54 // 成长值变化描述,用于管理侧显示
55 private String description;
56
57 // 创建时间
58 private Timestamp createTime;
59
60 // 更新时间
61 private Timestamp updateTime;
62 }
1 package com.topdraw.business.basicdata.exp.detail.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class ExpDetailQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.exp.detail.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.exp.detail.repository.ExpDetailRepository;
7 import com.topdraw.business.basicdata.exp.detail.service.ExpDetailService;
8 import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailDTO;
9 import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailQueryCriteria;
10 import com.topdraw.business.basicdata.exp.detail.service.mapper.ExpDetailMapper;
11 import org.redisson.api.RLock;
12 import org.redisson.api.RedissonClient;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service;
15 import org.springframework.transaction.annotation.Propagation;
16 import org.springframework.transaction.annotation.Transactional;
17 import org.springframework.dao.EmptyResultDataAccessException;
18 import org.springframework.data.domain.Page;
19 import org.springframework.data.domain.Pageable;
20 import org.springframework.util.Assert;
21 import com.topdraw.utils.PageUtil;
22 import com.topdraw.utils.QueryHelp;
23 import com.topdraw.utils.StringUtils;
24
25 import java.util.List;
26 import java.util.Map;
27
28 /**
29 * @author XiangHan
30 * @date 2021-10-22
31 */
32 @Service
33 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
34 public class ExpDetailServiceImpl implements ExpDetailService {
35
36 @Autowired
37 private ExpDetailRepository ExpDetailRepository;
38
39 @Autowired
40 private ExpDetailMapper ExpDetailMapper;
41
42 @Autowired
43 private RedissonClient redissonClient;
44
45 @Override
46 public Map<String, Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable) {
47 Page<ExpDetail> page = ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
48 return PageUtil.toPage(page.map(ExpDetailMapper::toDto));
49 }
50
51 @Override
52 public List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria) {
53 return ExpDetailMapper.toDto(ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
54 }
55
56 @Override
57 public ExpDetailDTO findById(Long id) {
58 ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseGet(ExpDetail::new);
59 ValidationUtil.isNull(ExpDetail.getId(),"ExpDetail","id",id);
60 return ExpDetailMapper.toDto(ExpDetail);
61 }
62
63 @Override
64 @Transactional(rollbackFor = Exception.class)
65 @AsyncMqSend()
66 public void create(ExpDetail resources) {
67 ExpDetailRepository.save(resources);
68 }
69
70 @Override
71 @Transactional(rollbackFor = Exception.class)
72 @AsyncMqSend()
73 public void update(ExpDetail resources) {
74 RLock rLock = this.redissonClient.getLock(resources.getId().toString());
75 try {
76 ExpDetail ExpDetail = ExpDetailRepository.findById(resources.getId()).orElseGet(ExpDetail::new);
77 ValidationUtil.isNull( ExpDetail.getId(),"ExpDetail","id",resources.getId());
78 ExpDetail.copy(resources);
79 ExpDetailRepository.save(ExpDetail);
80 } catch (Exception e) {
81 e.printStackTrace();
82 throw e;
83 } finally {
84 rLock.unlock();
85 }
86 }
87
88 @Override
89 @Transactional(rollbackFor = Exception.class)
90 @AsyncMqSend()
91 public void delete(Long id) {
92 Assert.notNull(id, "The given id must not be null!");
93 ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseThrow(
94 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpDetail.class, id), 1));
95 ExpDetailRepository.delete(ExpDetail);
96 }
97
98
99 @Override
100 public ExpDetailDTO getByCode(String code) {
101 return StringUtils.isNotEmpty(code) ? ExpDetailMapper.toDto(ExpDetailRepository.findFirstByCode(code).orElseGet(ExpDetail::new))
102 : new ExpDetailDTO();
103 }
104 }
1 package com.topdraw.business.basicdata.exp.detail.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail;
5 import com.topdraw.business.basicdata.exp.detail.service.dto.ExpDetailDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface ExpDetailMapper extends BaseMapper<ExpDetailDTO, ExpDetail> {
15
16 }
1 package com.topdraw.business.basicdata.exp.history.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_exp_history")
24 public class ExpHistory implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 标识
33 @Column(name = "code", nullable = false)
34 private String code;
35
36 // 会员id
37 @Column(name = "member_id", nullable = false)
38 private Long memberId;
39
40 // 账号id
41 @Column(name = "account_id")
42 private Long accountId;
43
44 // 原始成长值
45 @Column(name = "original_exp", nullable = false)
46 private Long originalExp;
47
48 // 结果成长值
49 @Column(name = "result_exp", nullable = false)
50 private Long resultExp;
51
52 // 成长值变化,一般为正数
53 @Column(name = "exp", nullable = false)
54 private Long exp;
55
56 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)4.系统赠送
57 @Column(name = "device_type", nullable = false)
58 private Integer deviceType;
59
60 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他
61 @Column(name = "evt_type", nullable = false)
62 private Integer evtType;
63
64 // 订单id(针对订购操作)
65 @Column(name = "order_id")
66 private Long orderId;
67
68 // 节目id(针对观影操作)
69 @Column(name = "media_id")
70 private Long mediaId;
71
72 // 活动id(针对参与活动)
73 @Column(name = "activity_id")
74 private Long activityId;
75
76 // 成长值变化描述,用于管理侧显示
77 @Column(name = "description", nullable = false)
78 private String description;
79
80 // 创建时间
81 @CreatedDate
82 @Column(name = "create_time")
83 private Timestamp createTime;
84
85 // 更新时间
86 @LastModifiedDate
87 @Column(name = "update_time")
88 private Timestamp updateTime;
89
90 public void copy(ExpHistory source){
91 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
92 }
93 }
1 package com.topdraw.business.basicdata.exp.history.repository;
2
3 import com.topdraw.business.basicdata.exp.history.domain.ExpHistory;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface ExpHistoryRepository extends JpaRepository<ExpHistory, Long>, JpaSpecificationExecutor<ExpHistory> {
14
15 Optional<ExpHistory> findFirstByCode(String code);
16 }
1 package com.topdraw.business.basicdata.exp.history.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.exp.history.domain.ExpHistory;
6 import com.topdraw.business.basicdata.exp.history.service.ExpHistoryService;
7 import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "ExpHistory管理")
19 @RestController
20 @RequestMapping("/api/ExpHistory")
21 public class ExpHistoryController {
22
23 @Autowired
24 private ExpHistoryService ExpHistoryService;
25
26 @GetMapping
27 @ApiOperation("查询ExpHistory")
28 public ResultInfo getExpHistorys(ExpHistoryQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(ExpHistoryService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有ExpHistory")
34 public ResultInfo getExpHistorys(ExpHistoryQueryCriteria criteria) {
35 return ResultInfo.success(ExpHistoryService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增ExpHistory")
41 public ResultInfo create(@Validated @RequestBody ExpHistory resources) {
42 ExpHistoryService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改ExpHistory")
49 public ResultInfo update(@Validated @RequestBody ExpHistory resources) {
50 ExpHistoryService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除ExpHistory")
58 public ResultInfo delete(@PathVariable Long id) {
59 ExpHistoryService.delete(id);
60 return ResultInfo.success();
61 }
62
63 @GetMapping(value = "/getByCode/{code}")
64 @ApiOperation(value = "根据标识查询")
65 public ResultInfo getByCode(@PathVariable String code) {
66 return ResultInfo.success(ExpHistoryService.getByCode(code));
67 }
68 }
1 package com.topdraw.business.basicdata.exp.history.service;
2
3 import com.topdraw.business.basicdata.exp.history.domain.ExpHistory;
4 import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryDTO;
5 import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface ExpHistoryService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<ExpHistoryDTO>
28 */
29 List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return ExpHistoryDTO
35 */
36 ExpHistoryDTO findById(Long id);
37
38 void create(ExpHistory resources);
39
40 void update(ExpHistory resources);
41
42 void delete(Long id);
43
44 /**
45 * Code校验
46 * @param code
47 * @return ExpHistoryDTO
48 */
49 ExpHistoryDTO getByCode(String code);
50 }
1 package com.topdraw.business.basicdata.exp.history.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class ExpHistoryDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 会员id
22 private Long memberId;
23
24 // 账号id
25 private Long accountId;
26
27 // 原始成长值
28 private Long originalExp;
29
30 // 结果成长值
31 private Long resultExp;
32
33 // 成长值变化,一般为正数
34 private Long exp;
35
36 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)4.系统赠送
37 private Integer deviceType;
38
39 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他
40 private Integer evtType;
41
42 // 订单id(针对订购操作)
43 private Long orderId;
44
45 // 节目id(针对观影操作)
46 private Long mediaId;
47
48 // 活动id(针对参与活动)
49 private Long activityId;
50
51 // 成长值变化描述,用于管理侧显示
52 private String description;
53
54 // 创建时间
55 private Timestamp createTime;
56
57 // 更新时间
58 private Timestamp updateTime;
59 }
1 package com.topdraw.business.basicdata.exp.history.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class ExpHistoryQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.exp.history.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.exp.history.domain.ExpHistory;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.exp.history.repository.ExpHistoryRepository;
7 import com.topdraw.business.basicdata.exp.history.service.ExpHistoryService;
8 import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryDTO;
9 import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryQueryCriteria;
10 import com.topdraw.business.basicdata.exp.history.service.mapper.ExpHistoryMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21 import com.topdraw.utils.StringUtils;
22
23 import java.util.List;
24 import java.util.Map;
25
26 /**
27 * @author XiangHan
28 * @date 2021-10-22
29 */
30 @Service
31 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
32 public class ExpHistoryServiceImpl implements ExpHistoryService {
33
34 @Autowired
35 private ExpHistoryRepository ExpHistoryRepository;
36
37 @Autowired
38 private ExpHistoryMapper ExpHistoryMapper;
39
40 @Override
41 public Map<String, Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable) {
42 Page<ExpHistory> page = ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
43 return PageUtil.toPage(page.map(ExpHistoryMapper::toDto));
44 }
45
46 @Override
47 public List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria) {
48 return ExpHistoryMapper.toDto(ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
49 }
50
51 @Override
52 public ExpHistoryDTO findById(Long id) {
53 ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseGet(ExpHistory::new);
54 ValidationUtil.isNull(ExpHistory.getId(),"ExpHistory","id",id);
55 return ExpHistoryMapper.toDto(ExpHistory);
56 }
57
58 @Override
59 @Transactional(rollbackFor = Exception.class)
60 // @AsyncMqSend()
61 public void create(ExpHistory resources) {
62 ExpHistoryRepository.save(resources);
63 }
64
65 @Override
66 @Transactional(rollbackFor = Exception.class)
67 @AsyncMqSend()
68 public void update(ExpHistory resources) {
69 ExpHistory ExpHistory = ExpHistoryRepository.findById(resources.getId()).orElseGet(ExpHistory::new);
70 ValidationUtil.isNull( ExpHistory.getId(),"ExpHistory","id",resources.getId());
71 ExpHistory.copy(resources);
72 ExpHistoryRepository.save(ExpHistory);
73 }
74
75 @Override
76 @Transactional(rollbackFor = Exception.class)
77 @AsyncMqSend()
78 public void delete(Long id) {
79 Assert.notNull(id, "The given id must not be null!");
80 ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseThrow(
81 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpHistory.class, id), 1));
82 ExpHistoryRepository.delete(ExpHistory);
83 }
84
85
86 @Override
87 public ExpHistoryDTO getByCode(String code) {
88 return StringUtils.isNotEmpty(code) ? ExpHistoryMapper.toDto(ExpHistoryRepository.findFirstByCode(code).orElseGet(ExpHistory::new))
89 : new ExpHistoryDTO();
90 }
91 }
1 package com.topdraw.business.basicdata.exp.history.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.exp.history.domain.ExpHistory;
5 import com.topdraw.business.basicdata.exp.history.service.dto.ExpHistoryDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface ExpHistoryMapper extends BaseMapper<ExpHistoryDTO, ExpHistory> {
15
16 }
1 package com.topdraw.business.basicdata.member.address.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_member_address")
24 public class MemberAddress implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 会员id
33 @Column(name = "member_id", nullable = false)
34 private Long memberId;
35
36 // 类型 1:家;2:公司;3:学校
37 @Column(name = "type", nullable = false)
38 private Integer type;
39
40 // 是否默认地址
41 @Column(name = "is_default", nullable = false)
42 private Integer isDefault;
43
44 // 显示顺序
45 @Column(name = "sequence")
46 private Integer sequence;
47
48 // 状态 0:不可用;1-可用
49 @Column(name = "status", nullable = false)
50 private Integer status;
51
52 // 联系人姓名
53 @Column(name = "contactor", nullable = false)
54 private String contactor;
55
56 // 联系人电话
57 @Column(name = "cellphone", nullable = false)
58 private String cellphone;
59
60 // 国家
61 @Column(name = "country", nullable = false)
62 private String country;
63
64 // 省份
65 @Column(name = "province", nullable = false)
66 private String province;
67
68 // 城市
69 @Column(name = "city", nullable = false)
70 private String city;
71
72 // 区县
73 @Column(name = "district", nullable = false)
74 private String district;
75
76 // 地址
77 @Column(name = "address", nullable = false)
78 private String address;
79
80 // 邮编
81 @Column(name = "zip_code")
82 private String zipCode;
83
84 // 创建时间
85 @CreatedDate
86 @Column(name = "create_time")
87 private Timestamp createTime;
88
89 // 更新时间
90 @LastModifiedDate
91 @Column(name = "update_time")
92 private Timestamp updateTime;
93
94 public void copy(MemberAddress source){
95 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
96 }
97 }
1 package com.topdraw.business.basicdata.member.address.repository;
2
3 import com.topdraw.business.basicdata.member.address.domain.MemberAddress;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2021-10-22
10 */
11 public interface MemberAddressRepository extends JpaRepository<MemberAddress, Long>, JpaSpecificationExecutor<MemberAddress> {
12
13 }
1 package com.topdraw.business.basicdata.member.address.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.member.address.domain.MemberAddress;
6 import com.topdraw.business.basicdata.member.address.service.MemberAddressService;
7 import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "MemberAddress管理")
19 @RestController
20 @RequestMapping("/api/MemberAddress")
21 public class MemberAddressController {
22
23 @Autowired
24 private MemberAddressService MemberAddressService;
25
26 @GetMapping(value = "/pageMemberAddress")
27 @ApiOperation("查询MemberAddress")
28 public ResultInfo pageMemberAddress(MemberAddressQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(MemberAddressService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/findById/{id}")
33 @ApiOperation("查询指定MemberAddress")
34 public ResultInfo findById(@PathVariable(value = "id") Long id) {
35 return ResultInfo.success(MemberAddressService.findById(id));
36 }
37
38 @Log
39 @PostMapping(value = "/create")
40 @ApiOperation("新增MemberAddress")
41 public ResultInfo create(@Validated @RequestBody MemberAddress resources) {
42 MemberAddressService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping(value = "/update")
48 @ApiOperation("修改MemberAddress")
49 public ResultInfo update(@Validated @RequestBody MemberAddress resources) {
50 MemberAddressService.update(resources);
51 return ResultInfo.success();
52 }
53
54 @Log
55 @DeleteMapping(value = "/delete/{id}")
56 @ApiOperation("删除MemberAddress")
57 public ResultInfo delete(@PathVariable Long id) {
58 MemberAddressService.delete(id);
59 return ResultInfo.success();
60 }
61
62 }
1 package com.topdraw.business.basicdata.member.address.service;
2
3 import com.topdraw.business.basicdata.member.address.domain.MemberAddress;
4 import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO;
5 import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface MemberAddressService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<MemberAddressDTO>
28 */
29 List<MemberAddressDTO> queryAll(MemberAddressQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return MemberAddressDTO
35 */
36 MemberAddressDTO findById(Long id);
37
38 void create(MemberAddress resources);
39
40 void update(MemberAddress resources);
41
42 void delete(Long id);
43
44 }
1 package com.topdraw.business.basicdata.member.address.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class MemberAddressDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 会员id
19 private Long memberId;
20
21 // 类型 1:家;2:公司;3:学校
22 private Integer type;
23
24 // 是否默认地址
25 private Integer isDefault;
26
27 // 显示顺序
28 private Integer sequence;
29
30 // 状态 0:不可用;1-可用
31 private Integer status;
32
33 // 联系人姓名
34 private String contactor;
35
36 // 联系人电话
37 private String cellphone;
38
39 // 国家
40 private String country;
41
42 // 省份
43 private String province;
44
45 // 城市
46 private String city;
47
48 // 区县
49 private String district;
50
51 // 地址
52 private String address;
53
54 // 邮编
55 private String zipCode;
56
57 // 创建时间
58 private Timestamp createTime;
59
60 // 更新时间
61 private Timestamp updateTime;
62 }
1 package com.topdraw.business.basicdata.member.address.service.dto;
2
3 import com.topdraw.annotation.Query;
4 import lombok.Data;
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-22
9 */
10 @Data
11 public class MemberAddressQueryCriteria{
12
13 @Query
14 private Long memberId;
15
16 }
1 package com.topdraw.business.basicdata.member.address.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.member.address.domain.MemberAddress;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.member.address.repository.MemberAddressRepository;
7 import com.topdraw.business.basicdata.member.address.service.MemberAddressService;
8 import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO;
9 import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria;
10 import com.topdraw.business.basicdata.member.address.service.mapper.MemberAddressMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21
22 import java.util.List;
23 import java.util.Map;
24
25 /**
26 * @author XiangHan
27 * @date 2021-10-22
28 */
29 @Service
30 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
31 public class MemberAddressServiceImpl implements MemberAddressService {
32
33 @Autowired
34 private MemberAddressRepository MemberAddressRepository;
35
36 @Autowired
37 private MemberAddressMapper MemberAddressMapper;
38
39 @Override
40 public Map<String, Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable) {
41 Page<MemberAddress> page = MemberAddressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
42 return PageUtil.toPage(page.map(MemberAddressMapper::toDto));
43 }
44
45 @Override
46 public List<MemberAddressDTO> queryAll(MemberAddressQueryCriteria criteria) {
47 return MemberAddressMapper.toDto(MemberAddressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
48 }
49
50 @Override
51 public MemberAddressDTO findById(Long id) {
52 MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseGet(MemberAddress::new);
53 ValidationUtil.isNull(MemberAddress.getId(),"MemberAddress","id",id);
54 return MemberAddressMapper.toDto(MemberAddress);
55 }
56
57 @Override
58 @Transactional(rollbackFor = Exception.class)
59 @AsyncMqSend()
60 public void create(MemberAddress resources) {
61 MemberAddressRepository.save(resources);
62 }
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 @AsyncMqSend()
67 public void update(MemberAddress resources) {
68 MemberAddress MemberAddress = MemberAddressRepository.findById(resources.getId()).orElseGet(MemberAddress::new);
69 ValidationUtil.isNull( MemberAddress.getId(),"MemberAddress","id",resources.getId());
70 MemberAddress.copy(resources);
71 MemberAddressRepository.save(MemberAddress);
72 }
73
74 @Override
75 @Transactional(rollbackFor = Exception.class)
76 @AsyncMqSend()
77 public void delete(Long id) {
78 Assert.notNull(id, "The given id must not be null!");
79 MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseThrow(
80 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberAddress.class, id), 1));
81 MemberAddressRepository.delete(MemberAddress);
82 }
83
84
85 }
1 package com.topdraw.business.basicdata.member.address.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.member.address.domain.MemberAddress;
5 import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface MemberAddressMapper extends BaseMapper<MemberAddressDTO, MemberAddress> {
15
16 }
1 package com.topdraw.business.basicdata.member.domain;
2
3 import cn.hutool.core.bean.BeanUtil;
4 import cn.hutool.core.bean.copier.CopyOptions;
5 import lombok.Data;
6 import lombok.experimental.Accessors;
7 import org.springframework.data.annotation.CreatedDate;
8 import org.springframework.data.annotation.LastModifiedDate;
9 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
10
11 import javax.persistence.*;
12 import java.io.Serializable;
13 import java.sql.Timestamp;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_member")
24 public class Member implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 标识
33 @Column(name = "code", nullable = false)
34 private String code;
35
36 // 类型 1:大屏;2:小屏
37 @Column(name = "`type`", nullable = false)
38 private Integer type;
39
40 // 状态 0:不可用;1:可用
41 @Column(name = "`status`", nullable = false)
42 private Integer status;
43
44 // 昵称 base64
45 @Column(name = "nickname")
46 private String nickname;
47
48 // 描述
49 @Column(name = "description")
50 private String description;
51
52 // 性别 0:女;1:男;-1:未知
53 @Column(name = "gender", nullable = false)
54 private Integer gender;
55
56 // 生日
57 @Column(name = "birthday")
58 private String birthday;
59
60 // 头像
61 @Column(name = "avatar_url")
62 private String avatarUrl;
63
64 // 分组信息
65 @Column(name = "`groups`")
66 private String groups;
67
68 // 标签
69 @Column(name = "tags")
70 private String tags;
71
72 // 是否会员 0:非会员;1:会员
73 @Column(name = "vip", nullable = false)
74 private Integer vip;
75
76 // 会员等级(对应level表的level字段,非id)
77 @Column(name = "`level`", nullable = false)
78 private Integer level;
79
80 // 成长值
81 @Column(name = "`exp`")
82 private Long exp;
83
84 // 当前积分
85 @Column(name = "`points`")
86 private Long points;
87
88 // 即将到期积分(一个月内)
89 @Column(name = "due_points")
90 private Long duePoints;
91
92 // 优惠券数量
93 @Column(name = "coupon_amount")
94 private Long couponAmount;
95
96 // 即将过期优惠券数量
97 @Column(name = "due_coupon_amount")
98 private Long dueCouponAmount;
99
100 // iptv账号id
101 @Column(name = "user_iptv_id")
102 private Long userIptvId;
103
104 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
105 @Column(name = "bind_iptv_platform_type")
106 private Integer bindIptvPlatformType;
107
108 // iptv账号绑定时间
109 @Column(name = "bind_iptv_time")
110 private Timestamp bindIptvTime;
111
112 // 创建时间
113 @CreatedDate
114 @Column(name = "create_time")
115 private Timestamp createTime;
116
117 // 更新时间
118 @LastModifiedDate
119 @Column(name = "update_time")
120 private Timestamp updateTime;
121
122 // 是否在黑名单 1:是;0否
123 // @Column(name = "black_status")
124 // private Integer blackStatus;
125
126 public void copy(Member source){
127 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
128 }
129 }
1 package com.topdraw.business.basicdata.member.level.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_member_level")
24 public class MemberLevel implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 标识
33 @Column(name = "code", nullable = false)
34 private String code;
35
36 // 名称
37 @Column(name = "name", nullable = false)
38 private String name;
39
40 // 状态 0:未启用;1:启用
41 @Column(name = "status", nullable = false)
42 private Integer status;
43
44 // 对应成长值
45 @Column(name = "exp_value", nullable = false)
46 private Long expValue;
47
48 // 等级(不可重复,数字越大等级越高)
49 @Column(name = "level", nullable = false)
50 private Integer level;
51
52 // 会员徽标
53 @Column(name = "icon_url")
54 private String iconUrl;
55
56 // 描述
57 @Column(name = "description")
58 private String description;
59
60 // 对应任务id,通过此字段可获得该等级所对应的权益
61 @Column(name = "task_id")
62 private Long taskId;
63
64 // 创建时间
65 @CreatedDate
66 @Column(name = "create_time")
67 private Timestamp createTime;
68
69 // 更新时间
70 @LastModifiedDate
71 @Column(name = "update_time")
72 private Timestamp updateTime;
73
74 public void copy(MemberLevel source){
75 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
76 }
77 }
1 package com.topdraw.business.basicdata.member.level.repository;
2
3 import com.topdraw.business.basicdata.member.level.domain.MemberLevel;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.List;
8 import java.util.Optional;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface MemberLevelRepository extends JpaRepository<MemberLevel, Long>, JpaSpecificationExecutor<MemberLevel> {
15
16 Optional<MemberLevel> findFirstByCode(String code);
17
18 List<MemberLevel> findByLevelAndStatus(Integer level, Integer status);
19 }
1 package com.topdraw.business.basicdata.member.level.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.member.level.domain.MemberLevel;
6 import com.topdraw.business.basicdata.member.level.service.MemberLevelService;
7 import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "MemberLevel管理")
19 @RestController
20 @RequestMapping("/api/MemberLevel")
21 public class MemberLevelController {
22
23 @Autowired
24 private MemberLevelService MemberLevelService;
25
26 @GetMapping
27 @ApiOperation("查询MemberLevel")
28 public ResultInfo getMemberLevels(MemberLevelQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(MemberLevelService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有MemberLevel")
34 public ResultInfo getMemberLevels(MemberLevelQueryCriteria criteria) {
35 return ResultInfo.success(MemberLevelService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增MemberLevel")
41 public ResultInfo create(@Validated @RequestBody MemberLevel resources) {
42 MemberLevelService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改MemberLevel")
49 public ResultInfo update(@Validated @RequestBody MemberLevel resources) {
50 MemberLevelService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除MemberLevel")
58 public ResultInfo delete(@PathVariable Long id) {
59 MemberLevelService.delete(id);
60 return ResultInfo.success();
61 }
62
63 @GetMapping(value = "/getByCode/{code}")
64 @ApiOperation(value = "根据标识查询")
65 public ResultInfo getByCode(@PathVariable String code) {
66 return ResultInfo.success(MemberLevelService.getByCode(code));
67 }
68 }
1 package com.topdraw.business.basicdata.member.level.service;
2
3 import com.topdraw.business.basicdata.member.level.domain.MemberLevel;
4 import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO;
5 import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface MemberLevelService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(MemberLevelQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<MemberLevelDTO>
28 */
29 List<MemberLevelDTO> queryAll(MemberLevelQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return MemberLevelDTO
35 */
36 MemberLevelDTO findById(Long id);
37
38 void create(MemberLevel resources);
39
40 void update(MemberLevel resources);
41
42 void delete(Long id);
43
44 /**
45 * Code校验
46 * @param code
47 * @return MemberLevelDTO
48 */
49 MemberLevelDTO getByCode(String code);
50
51 List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status);
52 }
1 package com.topdraw.business.basicdata.member.level.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class MemberLevelDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 名称
22 private String name;
23
24 // 状态 0:未启用;1:启用
25 private Integer status;
26
27 // 对应成长值
28 private Long expValue;
29
30 // 等级(不可重复,数字越大等级越高)
31 private Integer level;
32
33 // 会员徽标
34 private String iconUrl;
35
36 // 描述
37 private String description;
38
39 // 对应任务id,通过此字段可获得该等级所对应的权益
40 private Long taskId;
41
42 // 创建时间
43 private Timestamp createTime;
44
45 // 更新时间
46 private Timestamp updateTime;
47 }
1 package com.topdraw.business.basicdata.member.level.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class MemberLevelQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.member.level.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.member.level.domain.MemberLevel;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.member.level.repository.MemberLevelRepository;
7 import com.topdraw.business.basicdata.member.level.service.MemberLevelService;
8 import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO;
9 import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria;
10 import com.topdraw.business.basicdata.member.level.service.mapper.MemberLevelMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21 import com.topdraw.utils.StringUtils;
22
23 import java.util.List;
24 import java.util.Map;
25
26 /**
27 * @author XiangHan
28 * @date 2021-10-22
29 */
30 @Service
31 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
32 public class MemberLevelServiceImpl implements MemberLevelService {
33
34 @Autowired
35 private MemberLevelRepository MemberLevelRepository;
36
37 @Autowired
38 private MemberLevelMapper MemberLevelMapper;
39
40 @Override
41 public Map<String, Object> queryAll(MemberLevelQueryCriteria criteria, Pageable pageable) {
42 Page<MemberLevel> page = MemberLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
43 return PageUtil.toPage(page.map(MemberLevelMapper::toDto));
44 }
45
46 @Override
47 public List<MemberLevelDTO> queryAll(MemberLevelQueryCriteria criteria) {
48 return MemberLevelMapper.toDto(MemberLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
49 }
50
51 @Override
52 public MemberLevelDTO findById(Long id) {
53 MemberLevel MemberLevel = MemberLevelRepository.findById(id).orElseGet(MemberLevel::new);
54 ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id);
55 return MemberLevelMapper.toDto(MemberLevel);
56 }
57
58 @Override
59 @Transactional(rollbackFor = Exception.class)
60 @AsyncMqSend()
61 public void create(MemberLevel resources) {
62 MemberLevelRepository.save(resources);
63 }
64
65 @Override
66 @Transactional(rollbackFor = Exception.class)
67 @AsyncMqSend()
68 public void update(MemberLevel resources) {
69 MemberLevel MemberLevel = MemberLevelRepository.findById(resources.getId()).orElseGet(MemberLevel::new);
70 ValidationUtil.isNull( MemberLevel.getId(),"MemberLevel","id",resources.getId());
71 MemberLevel.copy(resources);
72 MemberLevelRepository.save(MemberLevel);
73 }
74
75 @Override
76 @Transactional(rollbackFor = Exception.class)
77 @AsyncMqSend()
78 public void delete(Long id) {
79 Assert.notNull(id, "The given id must not be null!");
80 MemberLevel MemberLevel = MemberLevelRepository.findById(id).orElseThrow(
81 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberLevel.class, id), 1));
82 MemberLevelRepository.delete(MemberLevel);
83 }
84
85
86 @Override
87 public MemberLevelDTO getByCode(String code) {
88 return StringUtils.isNotEmpty(code) ? MemberLevelMapper.toDto(MemberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new))
89 : new MemberLevelDTO();
90 }
91
92 @Override
93 public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) {
94 return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status));
95 }
96 }
1 package com.topdraw.business.basicdata.member.level.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.member.level.domain.MemberLevel;
5 import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface MemberLevelMapper extends BaseMapper<MemberLevelDTO, MemberLevel> {
15
16 }
1 package com.topdraw.business.basicdata.member.profile;
2
3 public interface DoSaveMemberProfileGroup {
4 }
1 package com.topdraw.business.basicdata.member.profile;
2
3 public interface DoUpdateMemberProfileGroup {
4 }
1 package com.topdraw.business.basicdata.member.profile.domain;
2
3 import com.topdraw.business.basicdata.member.profile.DoSaveMemberProfileGroup;
4 import com.topdraw.business.basicdata.member.profile.DoUpdateMemberProfileGroup;
5 import lombok.Data;
6 import lombok.experimental.Accessors;
7 import cn.hutool.core.bean.BeanUtil;
8 import cn.hutool.core.bean.copier.CopyOptions;
9 import javax.persistence.*;
10 import javax.validation.constraints.NotNull;
11
12 import org.springframework.data.annotation.CreatedDate;
13 import org.springframework.data.annotation.LastModifiedDate;
14 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
15 import java.sql.Timestamp;
16
17 import java.io.Serializable;
18
19 /**
20 * @author XiangHan
21 * @date 2021-10-22
22 */
23 @Entity
24 @Data
25 @EntityListeners(AuditingEntityListener.class)
26 @Accessors(chain = true)
27 @Table(name="uc_member_profile")
28 public class MemberProfile implements Serializable {
29
30 // 主键
31 @Id
32 @GeneratedValue(strategy = GenerationType.IDENTITY)
33 @Column(name = "id")
34 @NotNull(message = "【id】 not be null!!" , groups = DoUpdateMemberProfileGroup.class)
35 private Long id;
36
37 // 会员id
38 @NotNull(message = "【memberId】 not be null!!" , groups = DoSaveMemberProfileGroup.class)
39 @Column(name = "member_id", nullable = false)
40 private Long memberId;
41
42 // 姓名
43 @Column(name = "realname")
44 private String realname;
45
46 // 性别 0:女; 1:男 -1:未知
47 @Column(name = "gender", nullable = false)
48 @NotNull(message = "【gender】 not be null!!" , groups = {DoSaveMemberProfileGroup.class})
49 private Integer gender;
50
51 // 生日
52 @NotNull(message = "【memberId】 not be null!!" , groups = DoSaveMemberProfileGroup.class)
53 @Column(name = "birthday", nullable = false)
54 private Timestamp birthday;
55
56 // 星座
57 @Column(name = "constellation")
58 private String constellation;
59
60 // 身份证
61 @NotNull(message = "【idCard】 not be null!!" , groups = DoSaveMemberProfileGroup.class)
62 @Column(name = "id_card", nullable = false)
63 private String idCard;
64
65 // 电子邮件
66 @Column(name = "email")
67 private String email;
68
69 // 国家
70 @Column(name = "country")
71 private String country;
72
73 // 省份
74 @Column(name = "province")
75 private String province;
76
77 // 城市
78 @Column(name = "city")
79 private String city;
80
81 // 区县
82 @Column(name = "district")
83 private String district;
84
85 // 描述
86 @Column(name = "description")
87 private String description;
88
89 // 创建时间
90 @CreatedDate
91 @Column(name = "create_time")
92 private Timestamp createTime;
93
94 // 更新时间
95 @LastModifiedDate
96 @Column(name = "update_time")
97 private Timestamp updateTime;
98
99 public void copy(MemberProfile source){
100 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
101 }
102 }
1 package com.topdraw.business.basicdata.member.profile.repository;
2
3 import com.topdraw.business.basicdata.member.profile.domain.MemberProfile;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2021-10-22
10 */
11 public interface MemberProfileRepository extends JpaRepository<MemberProfile, Long>, JpaSpecificationExecutor<MemberProfile> {
12
13 }
1 package com.topdraw.business.basicdata.member.profile.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.member.profile.domain.MemberProfile;
6 import com.topdraw.business.basicdata.member.profile.service.MemberProfileService;
7 import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "MemberProfile管理")
19 @RestController
20 @RequestMapping("/api/MemberProfile")
21 public class MemberProfileController {
22
23 @Autowired
24 private MemberProfileService MemberProfileService;
25
26 /*@GetMapping
27 @ApiOperation("查询MemberProfile")
28 public ResultInfo getMemberProfiles(MemberProfileQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(MemberProfileService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有MemberProfile")
34 public ResultInfo getMemberProfiles(MemberProfileQueryCriteria criteria) {
35 return ResultInfo.success(MemberProfileService.queryAll(criteria));
36 }*/
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增MemberProfile")
41 public ResultInfo create(@Validated @RequestBody MemberProfile resources) {
42 MemberProfileService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改MemberProfile")
49 public ResultInfo update(@Validated @RequestBody MemberProfile resources) {
50 MemberProfileService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除MemberProfile")
58 public ResultInfo delete(@PathVariable Long id) {
59 MemberProfileService.delete(id);
60 return ResultInfo.success();
61 }
62
63 }
1 package com.topdraw.business.basicdata.member.profile.service;
2
3 import com.topdraw.business.basicdata.member.profile.domain.MemberProfile;
4 import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO;
5 import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface MemberProfileService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<MemberProfileDTO>
28 */
29 List<MemberProfileDTO> queryAll(MemberProfileQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return MemberProfileDTO
35 */
36 MemberProfileDTO findById(Long id);
37
38 void create(MemberProfile resources);
39
40 void update(MemberProfile resources);
41
42 void delete(Long id);
43
44 }
1 package com.topdraw.business.basicdata.member.profile.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class MemberProfileDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 会员id
19 private Long memberId;
20
21 // 姓名
22 private String realname;
23
24 // 性别 0:女; 1:男 -1:未知
25 private Integer gender;
26
27 // 生日
28 private Timestamp birthday;
29
30 // 星座
31 private String constellation;
32
33 // 身份证
34 private String idCard;
35
36 // 电子邮件
37 private String email;
38
39 // 国家
40 private String country;
41
42 // 省份
43 private String province;
44
45 // 城市
46 private String city;
47
48 // 区县
49 private String district;
50
51 // 描述
52 private String description;
53
54 // 创建时间
55 private Timestamp createTime;
56
57 // 更新时间
58 private Timestamp updateTime;
59 }
1 package com.topdraw.business.basicdata.member.profile.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class MemberProfileQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.member.profile.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.member.profile.domain.MemberProfile;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.member.profile.repository.MemberProfileRepository;
7 import com.topdraw.business.basicdata.member.profile.service.MemberProfileService;
8 import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO;
9 import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria;
10 import com.topdraw.business.basicdata.member.profile.service.mapper.MemberProfileMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21
22 import java.util.List;
23 import java.util.Map;
24
25 /**
26 * @author XiangHan
27 * @date 2021-10-22
28 */
29 @Service
30 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
31 public class MemberProfileServiceImpl implements MemberProfileService {
32
33 @Autowired
34 private MemberProfileRepository MemberProfileRepository;
35
36 @Autowired
37 private MemberProfileMapper MemberProfileMapper;
38
39 @Override
40 public Map<String, Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable) {
41 Page<MemberProfile> page = MemberProfileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
42 return PageUtil.toPage(page.map(MemberProfileMapper::toDto));
43 }
44
45 @Override
46 public List<MemberProfileDTO> queryAll(MemberProfileQueryCriteria criteria) {
47 return MemberProfileMapper.toDto(MemberProfileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
48 }
49
50 @Override
51 public MemberProfileDTO findById(Long id) {
52 MemberProfile MemberProfile = MemberProfileRepository.findById(id).orElseGet(MemberProfile::new);
53 ValidationUtil.isNull(MemberProfile.getId(),"MemberProfile","id",id);
54 return MemberProfileMapper.toDto(MemberProfile);
55 }
56
57 @Override
58 @Transactional(rollbackFor = Exception.class)
59 @AsyncMqSend()
60 public void create(MemberProfile resources) {
61 MemberProfileRepository.save(resources);
62 }
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 @AsyncMqSend()
67 public void update(MemberProfile resources) {
68 MemberProfile MemberProfile = MemberProfileRepository.findById(resources.getId()).orElseGet(MemberProfile::new);
69 ValidationUtil.isNull( MemberProfile.getId(),"MemberProfile","id",resources.getId());
70 MemberProfile.copy(resources);
71 MemberProfileRepository.save(MemberProfile);
72 }
73
74 @Override
75 @Transactional(rollbackFor = Exception.class)
76 @AsyncMqSend()
77 public void delete(Long id) {
78 Assert.notNull(id, "The given id must not be null!");
79 MemberProfile MemberProfile = MemberProfileRepository.findById(id).orElseThrow(
80 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberProfile.class, id), 1));
81 MemberProfileRepository.delete(MemberProfile);
82 }
83
84
85 }
1 package com.topdraw.business.basicdata.member.profile.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.member.profile.domain.MemberProfile;
5 import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface MemberProfileMapper extends BaseMapper<MemberProfileDTO, MemberProfile> {
15
16 }
1 package com.topdraw.business.basicdata.member.relatedinfo.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_member_related_info")
24 public class MemberRelatedInfo implements Serializable {
25
26 // ID
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 会员id
33 @Column(name = "member_id", nullable = false)
34 private Long memberId;
35
36 // 人物关系 0:子女;1:父母
37 @Column(name = "type")
38 private Integer type;
39
40 // 手机号
41 @Column(name = "cellphone")
42 private String cellphone;
43
44 // 身份证号
45 @Column(name = "id_card")
46 private String idCard;
47
48 // 姓名
49 @Column(name = "name")
50 private String name;
51
52 // 性别 0:女;1:男;-1:未知
53 @Column(name = "sex")
54 private Integer sex;
55
56 // 创建时间
57 @CreatedDate
58 @Column(name = "create_time")
59 private Timestamp createTime;
60
61 // 更新时间
62 @LastModifiedDate
63 @Column(name = "update_time")
64 private Timestamp updateTime;
65
66 public void copy(MemberRelatedInfo source){
67 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
68 }
69 }
1 package com.topdraw.business.basicdata.member.relatedinfo.repository;
2
3 import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2021-10-22
10 */
11 public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> {
12
13 }
1 package com.topdraw.business.basicdata.member.relatedinfo.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo;
6 import com.topdraw.business.basicdata.member.relatedinfo.service.MemberRelatedInfoService;
7 import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.PageRequest;
10 import org.springframework.data.domain.Pageable;
11 import org.springframework.validation.annotation.Validated;
12 import org.springframework.web.bind.annotation.*;
13 import io.swagger.annotations.*;
14
15 /**
16 * @author XiangHan /api/MemberRelatedInfo
17 * @date 2021-10-22
18 */
19 @Api(tags = "MemberRelatedInfo管理")
20 @RestController
21 @RequestMapping("/api/MemberRelatedInfo")
22 public class MemberRelatedInfoController {
23
24 @Autowired
25 private MemberRelatedInfoService MemberRelatedInfoService;
26
27 @GetMapping(value = "/pageMemberRelatedInfos")
28 @ApiOperation("查询MemberRelatedInfo")
29 public ResultInfo pageMemberRelatedInfos(@Validated MemberRelatedInfoQueryCriteria criteria, Pageable pageable) {
30 return ResultInfo.successPage(MemberRelatedInfoService.queryAll(criteria,pageable));
31 }
32
33 @Log
34 @PostMapping(value = "/create")
35 @ApiOperation("新增MemberRelatedInfo")
36 public ResultInfo create(@Validated @RequestBody MemberRelatedInfo resources) {
37 MemberRelatedInfoService.create(resources);
38 return ResultInfo.success();
39 }
40
41 @Log
42 @PutMapping(value = "/update")
43 @ApiOperation("修改MemberRelatedInfo")
44 public ResultInfo update(@Validated @RequestBody MemberRelatedInfo resources) {
45 MemberRelatedInfoService.update(resources);
46 return ResultInfo.success();
47 }
48
49 @GetMapping(value = "/findById/{id}")
50 @ApiOperation("查询指定MemberRelatedInfo")
51 public ResultInfo findById(@PathVariable("id") Long id) {
52 return ResultInfo.success(MemberRelatedInfoService.findById(id));
53 }
54
55 @Log
56 @DeleteMapping(value = "/delete//{id}")
57 @ApiOperation("删除MemberRelatedInfo")
58 public ResultInfo delete(@PathVariable Long id) {
59 MemberRelatedInfoService.delete(id);
60 return ResultInfo.success();
61 }
62
63 }
1 package com.topdraw.business.basicdata.member.relatedinfo.service;
2
3 import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo;
4 import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO;
5 import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface MemberRelatedInfoService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<MemberRelatedInfoDTO>
28 */
29 List<MemberRelatedInfoDTO> queryAll(MemberRelatedInfoQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return MemberRelatedInfoDTO
35 */
36 MemberRelatedInfoDTO findById(Long id);
37
38 void create(MemberRelatedInfo resources);
39
40 void update(MemberRelatedInfo resources);
41
42 void delete(Long id);
43
44 }
1 package com.topdraw.business.basicdata.member.relatedinfo.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class MemberRelatedInfoDTO implements Serializable {
14
15 // ID
16 private Long id;
17
18 // 会员id
19 private Long memberId;
20
21 // 人物关系 0:子女;1:父母
22 private Integer type;
23
24 // 手机号
25 private String cellphone;
26
27 // 身份证号
28 private String idCard;
29
30 // 姓名
31 private String name;
32
33 // 性别 0:女;1:男;-1:未知
34 private Integer sex;
35
36 // 创建时间
37 private Timestamp createTime;
38
39 // 更新时间
40 private Timestamp updateTime;
41 }
1 package com.topdraw.business.basicdata.member.relatedinfo.service.dto;
2
3 import com.topdraw.annotation.Query;
4 import lombok.Data;
5
6 import javax.validation.constraints.NotNull;
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class MemberRelatedInfoQueryCriteria{
14
15 @Query
16 private Long memberId;
17
18
19
20 }
1 package com.topdraw.business.basicdata.member.relatedinfo.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.member.relatedinfo.repository.MemberRelatedInfoRepository;
7 import com.topdraw.business.basicdata.member.relatedinfo.service.MemberRelatedInfoService;
8 import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO;
9 import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria;
10 import com.topdraw.business.basicdata.member.relatedinfo.service.mapper.MemberRelatedInfoMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21
22 import java.util.List;
23 import java.util.Map;
24
25 /**
26 * @author XiangHan
27 * @date 2021-10-22
28 */
29 @Service
30 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
31 public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService {
32
33 @Autowired
34 private MemberRelatedInfoRepository MemberRelatedInfoRepository;
35
36 @Autowired
37 private MemberRelatedInfoMapper MemberRelatedInfoMapper;
38
39 @Override
40 public Map<String, Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable) {
41 Page<MemberRelatedInfo> page = MemberRelatedInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
42 return PageUtil.toPage(page.map(MemberRelatedInfoMapper::toDto));
43 }
44
45 @Override
46 public List<MemberRelatedInfoDTO> queryAll(MemberRelatedInfoQueryCriteria criteria) {
47 return MemberRelatedInfoMapper.toDto(MemberRelatedInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
48 }
49
50 @Override
51 public MemberRelatedInfoDTO findById(Long id) {
52 MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseGet(MemberRelatedInfo::new);
53 ValidationUtil.isNull(MemberRelatedInfo.getId(),"MemberRelatedInfo","id",id);
54 return MemberRelatedInfoMapper.toDto(MemberRelatedInfo);
55 }
56
57 @Override
58 @Transactional(rollbackFor = Exception.class)
59 @AsyncMqSend()
60 public void create(MemberRelatedInfo resources) {
61 MemberRelatedInfoRepository.save(resources);
62 }
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 @AsyncMqSend()
67 public void update(MemberRelatedInfo resources) {
68 MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new);
69 ValidationUtil.isNull( MemberRelatedInfo.getId(),"MemberRelatedInfo","id",resources.getId());
70 MemberRelatedInfo.copy(resources);
71 MemberRelatedInfoRepository.save(MemberRelatedInfo);
72 }
73
74 @Override
75 @Transactional(rollbackFor = Exception.class)
76 @AsyncMqSend()
77 public void delete(Long id) {
78 Assert.notNull(id, "The given id must not be null!");
79 MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseThrow(
80 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberRelatedInfo.class, id), 1));
81 MemberRelatedInfoRepository.delete(MemberRelatedInfo);
82 }
83
84
85 }
1 package com.topdraw.business.basicdata.member.relatedinfo.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo;
5 import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface MemberRelatedInfoMapper extends BaseMapper<MemberRelatedInfoDTO, MemberRelatedInfo> {
15
16 }
1 package com.topdraw.business.basicdata.member.repository;
2
3 import com.topdraw.business.basicdata.member.domain.Member;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecificationExecutor<Member> {
14
15 Optional<Member> findFirstByCode(String code);
16 }
1 package com.topdraw.business.basicdata.member.rest;
2
3 import com.topdraw.annotation.Log;
4 import com.topdraw.business.basicdata.member.domain.Member;
5 import com.topdraw.business.basicdata.member.service.MemberService;
6 import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria;
7 import com.topdraw.common.ResultInfo;
8 import io.swagger.annotations.Api;
9 import io.swagger.annotations.ApiOperation;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.data.domain.Pageable;
12 import org.springframework.util.Assert;
13 import org.springframework.validation.annotation.Validated;
14 import org.springframework.web.bind.annotation.*;
15
16 /**
17 * @author XiangHan
18 * @date 2021-10-22
19 */
20 @Api(tags = "Member管理")
21 @RestController
22 @RequestMapping("/api/member")
23 public class MemberController {
24
25 @Autowired
26 private MemberService memberService;
27
28 /* @GetMapping(value = "/pageMembers")
29 @ApiOperation("查询Member")
30 public ResultInfo pageMembers(MemberQueryCriteria criteria, Pageable pageable) {
31 return ResultInfo.successPage(memberService.queryAll(criteria,pageable));
32 }
33
34 @GetMapping(value = "/findById/{id}")
35 @ApiOperation("查询指定Member")
36 public ResultInfo findById(@PathVariable("id") Long id) {
37 return ResultInfo.success(memberService.findById(id));
38 }
39 */
40 @Log
41 @PostMapping(value = "/create")
42 @ApiOperation("新增Member")
43 public ResultInfo create(@Validated @RequestBody Member resources) {
44 Long id = memberService.create(resources);
45 return ResultInfo.success(id);
46 }
47
48 @Log
49 @PutMapping(value = "/doUpdateVip")
50 @ApiOperation("修改Member等级")
51 public ResultInfo doUpdateVip(Long memberId , Integer vip) {
52 Assert.isNull(memberId,"MemberController -->> doUpdateVip -->>【memberId】 not be null!!");
53 Assert.isNull(vip,"MemberController -->> doUpdateVip -->>【memberId】 not be null!!");
54 Member member = new Member();
55 member.setId(memberId);
56 member.setVip(vip);
57 memberService.update(member);
58 return ResultInfo.success();
59 }
60
61 @Log
62 @PutMapping(value = "/update")
63 @ApiOperation("修改Member")
64 public ResultInfo update(@Validated @RequestBody Member resources) {
65 memberService.update(resources);
66 return ResultInfo.success();
67 }
68
69 @GetMapping(value = "/getByCode/{code}")
70 @ApiOperation(value = "根据标识查询")
71 public ResultInfo getByCode(@PathVariable String code) {
72 return ResultInfo.success(memberService.getByCode(code));
73 }
74 }
1 package com.topdraw.business.basicdata.member.service;
2
3 import com.topdraw.business.basicdata.member.domain.Member;
4 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
5 import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7
8 import java.util.List;
9 import java.util.Map;
10
11 /**
12 * @author XiangHan
13 * @date 2021-10-22
14 */
15 public interface MemberService {
16
17 /**
18 * 查询数据分页
19 * @param criteria 条件参数
20 * @param pageable 分页参数
21 * @return Map<String,Object>
22 */
23 Map<String,Object> queryAll(MemberQueryCriteria criteria, Pageable pageable);
24
25 /**
26 * 查询所有数据不分页
27 * @param criteria 条件参数
28 * @return List<MemberDTO>
29 */
30 List<MemberDTO> queryAll(MemberQueryCriteria criteria);
31
32 /**
33 * 根据ID查询
34 * @param id ID
35 * @return MemberDTO
36 */
37 MemberDTO findById(Long id);
38
39 Long create(Member resources);
40
41 void update(Member resources);
42
43 void delete(Long id);
44
45 /**
46 * Code校验
47 * @param code
48 * @return MemberDTO
49 */
50 MemberDTO getByCode(String code);
51 }
1 package com.topdraw.business.basicdata.member.service.dto;
2
3 import lombok.Data;
4
5 import java.io.Serializable;
6 import java.sql.Timestamp;
7
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Data
14 public class MemberDTO implements Serializable {
15
16 // 主键
17 private Long id;
18
19 // 标识
20 private String code;
21
22 // 类型 1:大屏;2:小屏
23 private Integer type;
24
25 // 状态 0:不可用;1:可用
26 private Integer status;
27
28 // 昵称 base64
29 private String nickname;
30
31 // 描述
32 private String description;
33
34 // 性别 0:女;1:男;-1:未知
35 private Integer gender;
36
37 // 生日
38 private String birthday;
39
40 // 头像
41 private String avatarUrl;
42
43 // 分组信息
44 private String groups;
45
46 // 标签
47 private String tags;
48
49 // 是否会员 0:非会员;1:会员
50 private Integer vip;
51
52 // 会员等级(对应level表的level字段,非id)
53 private Integer level;
54
55 // 成长值
56 private Long exp;
57
58 // 当前积分
59 private Long points;
60
61 // 即将到期积分(一个月内)
62 private Long duePoints;
63
64 // 优惠券数量
65 private Long couponAmount;
66
67 // 即将过期优惠券数量
68 private Long dueCouponAmount;
69
70 // iptv账号id
71 private Long userIptvId;
72
73 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
74 private Integer bindIptvPlatformType;
75
76 // iptv账号绑定时间
77 private Timestamp bindIptvTime;
78
79 // 创建时间
80 private Timestamp createTime;
81
82 // 更新时间
83 private Timestamp updateTime;
84
85 // 是否在黑名单 1:是;0否
86 // private Integer blackStatus;
87 }
1 package com.topdraw.business.basicdata.member.service.dto;
2
3 import com.topdraw.annotation.Query;
4 import lombok.Data;
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-22
9 */
10 @Data
11 public class MemberQueryCriteria{
12
13 @Query(type = Query.Type.LEFT_LIKE)
14 private String code;
15
16 // 类型 1:大屏;2:小屏
17 @Query(type = Query.Type.EQUAL)
18 private Integer type;
19
20 // 状态 0:不可用;1:可用
21 @Query(type = Query.Type.EQUAL)
22 private Integer status;
23
24 // 昵称 base64
25 @Query(type = Query.Type.LEFT_LIKE)
26 private String nickname;
27
28 // 性别 0:女;1:男;-1:未知
29 @Query(type = Query.Type.EQUAL)
30 private Integer gender;
31
32 // 分组信息
33 @Query(type = Query.Type.EQUAL)
34 private String groups;
35
36 // 标签
37 @Query(type = Query.Type.IN)
38 private String tags;
39
40 // 是否会员 0:非会员;1:会员
41 @Query(type = Query.Type.EQUAL)
42 private Integer vip;
43
44 // 会员等级(对应level表的level字段,非id)
45 @Query(type = Query.Type.EQUAL)
46 private Integer level;
47
48 // iptv账号id
49 @Query(type = Query.Type.EQUAL)
50 private Long userIptvId;
51
52 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
53 @Query(type = Query.Type.IN)
54 private Integer bindIptvPlatformType;
55
56 }
1 package com.topdraw.business.basicdata.member.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.member.domain.Member;
5 import com.topdraw.business.basicdata.member.repository.MemberRepository;
6 import com.topdraw.business.basicdata.member.service.MemberService;
7 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
8 import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria;
9 import com.topdraw.business.basicdata.member.service.mapper.MemberMapper;
10 import com.topdraw.mq.config.RabbitMqConfig;
11 import com.topdraw.util.IdWorker;
12 import com.topdraw.util.RedissonUtil;
13 import com.topdraw.util.TimestampUtil;
14 import com.topdraw.utils.PageUtil;
15 import com.topdraw.utils.QueryHelp;
16 import com.topdraw.utils.StringUtils;
17 import com.topdraw.utils.ValidationUtil;
18 import org.redisson.api.RLock;
19 import org.redisson.api.RedissonClient;
20 import org.springframework.beans.BeanUtils;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.dao.EmptyResultDataAccessException;
23 import org.springframework.data.domain.Page;
24 import org.springframework.data.domain.Pageable;
25 import org.springframework.stereotype.Service;
26 import org.springframework.transaction.annotation.Propagation;
27 import org.springframework.transaction.annotation.Transactional;
28 import org.springframework.util.Assert;
29
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Objects;
33
34 /**
35 * @author XiangHan
36 * @date 2021-10-22
37 */
38 @Service
39 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
40 public class MemberServiceImpl implements MemberService {
41
42 @Autowired
43 private MemberRepository memberRepository;
44
45 @Autowired
46 private MemberMapper memberMapper;
47
48 @Autowired
49 private RedissonClient redissonClient;
50
51 @Override
52 public Map<String, Object> queryAll(MemberQueryCriteria criteria, Pageable pageable) {
53 Page<Member> page = memberRepository.findAll((root, criteriaQuery, criteriaBuilder)
54 -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
55 return PageUtil.toPage(page.map(memberMapper::toDto));
56 }
57
58 @Override
59 public List<MemberDTO> queryAll(MemberQueryCriteria criteria) {
60 return memberMapper.toDto(memberRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
61 }
62
63 @Override
64 public MemberDTO findById(Long id) {
65 Member member = memberRepository.findById(id).orElseGet(Member::new);
66 ValidationUtil.isNull(member.getId(),"Member","id",id);
67 return memberMapper.toDto(member);
68 }
69
70 @Override
71 @Transactional(rollbackFor = Exception.class)
72 @AsyncMqSend()
73 public Long create(Member resources) {
74 Member member = this.checkMemberData(resources);
75 memberRepository.save(member);
76 return member.getId();
77 }
78
79 private Member checkMemberData(Member member) {
80 Long defaultValue = 0L;
81 member.setCode(String.valueOf(IdWorker.generator()));
82 Integer gender = member.getGender();
83 member.setGender(Objects.nonNull(gender) ? gender : 0);
84 Integer type = member.getType();
85 member.setType(Objects.nonNull(type) ? type:-1);
86 Integer status = member.getStatus();
87 member.setStatus(Objects.nonNull(status) ? status:1);
88 Integer vip = member.getVip();
89 member.setVip(Objects.nonNull(vip) ? status:0);
90 Integer level = member.getLevel();
91 member.setLevel(Objects.nonNull(level) ? level:0);
92 member.setExp(defaultValue);
93 member.setPoints(defaultValue);
94 member.setDuePoints(defaultValue);
95 member.setCouponAmount(defaultValue);
96 member.setDueCouponAmount(defaultValue);
97 return member;
98 }
99
100 @Override
101 @Transactional(rollbackFor = Exception.class)
102 @AsyncMqSend()
103 public void update(Member resources) {
104 RLock rLock = this.redissonClient.getLock("updateMember" + resources.getId().toString());
105 try {
106 RedissonUtil.lock(rLock);
107 Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new);
108 ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId());
109 member.copy(resources);
110 memberRepository.save(member);
111 } catch (Exception e) {
112 e.printStackTrace();
113 throw e;
114 } finally {
115 RedissonUtil.unlock(rLock);
116 }
117 }
118
119 @Override
120 @Transactional(rollbackFor = Exception.class)
121 @AsyncMqSend()
122 public void delete(Long id) {
123 Assert.notNull(id, "The given id must not be null!");
124 Member member = memberRepository.findById(id).orElseThrow(
125 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Member.class, id), 1));
126 memberRepository.delete(member);
127 }
128
129
130 @Override
131 public MemberDTO getByCode(String code) {
132 return StringUtils.isNotEmpty(code) ? memberMapper.toDto(memberRepository.findFirstByCode(code).orElseGet(Member::new))
133 : new MemberDTO();
134 }
135 }
1 package com.topdraw.business.basicdata.member.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.member.domain.Member;
5 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface MemberMapper extends BaseMapper<MemberDTO, Member> {
15
16 }
1 package com.topdraw.business.basicdata.points.available.domain;
2
3 import com.fasterxml.jackson.annotation.JsonFormat;
4 import lombok.Data;
5 import lombok.experimental.Accessors;
6 import cn.hutool.core.bean.BeanUtil;
7 import cn.hutool.core.bean.copier.CopyOptions;
8 import javax.persistence.*;
9 import org.springframework.data.annotation.CreatedDate;
10 import org.springframework.data.annotation.LastModifiedDate;
11 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
12 import java.sql.Timestamp;
13 import java.util.UUID;
14
15 import java.io.Serializable;
16
17 /**
18 * 每天定时扫描可用积分表,将过期积分删除,并及时更新积分明细表和积分总额表
19 *
20 * @author XiangHan
21 * @date 2021-10-23
22 */
23 @Entity
24 @Data
25 @EntityListeners(AuditingEntityListener.class)
26 @Accessors(chain = true)
27 @Table(name="uc_points_available")
28 public class PointsAvailable implements Serializable {
29
30 // 主键
31 @Id
32 @GeneratedValue(strategy = GenerationType.IDENTITY)
33 @Column(name = "id")
34 private Long id;
35
36 // 标识
37 @Column(name = "code")
38 private String code;
39
40 // 积分类型 0:通用型
41 @Column(name = "points_type")
42 private Integer pointsType;
43
44 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
45 @Column(name = "device_type")
46 private Integer deviceType;
47
48 // 会员id
49 @Column(name = "member_id", nullable = false)
50 private Long memberId;
51
52 // 积分值
53 @Column(name = "points")
54 private Long points;
55
56 // 过期时间
57 @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
58 @Column(name = "expire_time")
59 private Timestamp expireTime;
60
61 // 描述
62 @Column(name = "description")
63 private String description;
64
65 // 创建时间
66 @CreatedDate
67 @Column(name = "create_time")
68 private Timestamp createTime;
69
70 // 更新时间
71 @LastModifiedDate
72 @Column(name = "update_time")
73 private Timestamp updateTime;
74
75 public void copy(PointsAvailable source){
76 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
77 }
78 }
1 package com.topdraw.business.basicdata.points.available.repository;
2
3 import com.topdraw.business.basicdata.points.available.domain.PointsAvailable;
4 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
5 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria;
6 import org.springframework.data.jpa.repository.JpaRepository;
7 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
8 import org.springframework.data.jpa.repository.Modifying;
9 import org.springframework.data.jpa.repository.Query;
10 import org.springframework.transaction.annotation.Transactional;
11
12 import java.sql.Timestamp;
13 import java.util.Date;
14 import java.util.List;
15 import java.util.Optional;
16
17 /**
18 * @author XiangHan
19 * @date 2021-10-23
20 */
21 public interface PointsAvailableRepository extends JpaRepository<PointsAvailable, Long>, JpaSpecificationExecutor<PointsAvailable> {
22
23 Optional<PointsAvailable> findFirstByCode(String code);
24
25 List<PointsAvailableDTO> findByMemberId(Long memberId);
26
27 List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId , Date now);
28
29 /**
30 * 即将过期的积分
31 * @param memberId
32 * @param factor
33 * @return
34 */
35 @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 " +
36 " and (TO_DAYS(expire_time) - TO_DAYS(NOW())) <= ?2 "
37 ,nativeQuery = true)
38 Long findSoonExpireTime(Long memberId, Integer factor);
39
40
41
42 /**
43 * 总积分
44 * @param criteria
45 * @return
46 */
47 @Deprecated
48 @Query(value = "SELECT sum(upa.points) AS pointsProduce FROM uc_points_available upa WHERE (TO_DAYS(create_time)+1) = TO_DAYS(NOW())"
49 ,nativeQuery = true)
50 Long findEveryDayPointsProduce(PointsAvailableQueryCriteria criteria);
51
52 /**
53 * 可用总积分
54 * @param criteria
55 * @return
56 */
57 @Deprecated
58 @Query(value = "SELECT sum(upa.points) AS pointsAvailable FROM uc_points_available upa WHERE (TO_DAYS(create_time)+1) = TO_DAYS(NOW())"
59 ,nativeQuery = true)
60 Long findEveryDayPointsAvailable(PointsAvailableQueryCriteria criteria);
61
62 /**
63 * 过期总积分
64 * @param criteria
65 * @return
66 */
67 @Deprecated
68 @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where (TO_DAYS(create_time)+1) = TO_DAYS(NOW()) " +
69 " and TO_DAYS(expire_time) < TO_DAYS(NOW())"
70 ,nativeQuery = true)
71 Long findEveryDayPointsExpire(PointsAvailableQueryCriteria criteria);
72
73 /**
74 * 获取可用积分
75 * @param memberId
76 * @return
77 */
78 @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and upa.expire_time >= now()"
79 ,nativeQuery = true)
80 long findAvailablePointsByMemberId(long memberId);
81
82 List<PointsAvailable> findByMemberIdOrderByExpireTime(Long memberId);
83
84 @Transactional
85 @Modifying
86 @Query(value = "delete from uc_points_available where id in ?1" ,nativeQuery = true)
87 void deleteBatchByIds(List<Long> id);
88
89 List<PointsAvailable> findByExpireTimeBefore(Timestamp now);
90 }
1 package com.topdraw.business.basicdata.points.available.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.points.available.domain.PointsAvailable;
6 import com.topdraw.business.basicdata.points.available.service.PointsAvailableService;
7 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.http.HttpStatus;
11 import org.springframework.http.ResponseEntity;
12 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.*;
14 import io.swagger.annotations.*;
15 import java.io.IOException;
16 import javax.servlet.http.HttpServletResponse;
17
18 /**
19 * @author XiangHan
20 * @date 2021-10-23
21 */
22 //@Api(tags = "PointsAvailable管理")
23 //@RestController
24 //@RequestMapping("/api/PointsAvailable")
25 public class PointsAvailableController {
26
27 /*@Autowired
28 private PointsAvailableService PointsAvailableService;
29
30 @GetMapping
31 @ApiOperation("查询PointsAvailable")
32 public ResultInfo getPointsAvailables(PointsAvailableQueryCriteria criteria, Pageable pageable) {
33 return ResultInfo.successPage(PointsAvailableService.queryAll(criteria,pageable));
34 }
35
36 @GetMapping(value = "/all")
37 @ApiOperation("查询所有PointsAvailable")
38 public ResultInfo getPointsAvailables(PointsAvailableQueryCriteria criteria) {
39 return ResultInfo.success(PointsAvailableService.queryAll(criteria));
40 }
41
42 @Log
43 @PostMapping
44 @ApiOperation("新增PointsAvailable")
45 public ResultInfo create(@Validated @RequestBody PointsAvailable resources) {
46 PointsAvailableService.create(resources);
47 return ResultInfo.success();
48 }
49
50 @Log
51 @PutMapping
52 @ApiOperation("修改PointsAvailable")
53 public ResultInfo update(@Validated @RequestBody PointsAvailable resources) {
54 PointsAvailableService.update(resources);
55 return ResultInfo.success();
56 }
57
58
59 @Log
60 @DeleteMapping(value = "/{id}")
61 @ApiOperation("删除PointsAvailable")
62 public ResultInfo delete(@PathVariable Long id) {
63 PointsAvailableService.delete(id);
64 return ResultInfo.success();
65 }
66
67 @GetMapping(value = "/getByCode/{code}")
68 @ApiOperation(value = "根据标识查询")
69 public ResultInfo getByCode(@PathVariable String code) {
70 return ResultInfo.success(PointsAvailableService.getByCode(code));
71 }*/
72 }
1 package com.topdraw.business.basicdata.points.available.service;
2
3 import com.topdraw.business.basicdata.points.available.domain.PointsAvailable;
4 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
5 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria;
6 import com.topdraw.business.process.domian.TempPoints;
7 import org.springframework.data.domain.Pageable;
8
9 import java.sql.Timestamp;
10 import java.util.Date;
11 import java.util.Map;
12 import java.util.List;
13 import java.io.IOException;
14 import javax.servlet.http.HttpServletResponse;
15
16 /**
17 * @author XiangHan
18 * @date 2021-10-23
19 */
20 public interface PointsAvailableService {
21
22 /**
23 * 查询数据分页
24 * @param criteria 条件参数
25 * @param pageable 分页参数
26 * @return Map<String,Object>
27 */
28 Map<String,Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable);
29
30 /**
31 * 查询所有数据不分页
32 * @param criteria 条件参数
33 * @return List<PointsAvailableDTO>
34 */
35 List<PointsAvailableDTO> queryAll(PointsAvailableQueryCriteria criteria);
36
37 /**
38 * 根据ID查询
39 * @param id ID
40 * @return PointsAvailableDTO
41 */
42 PointsAvailableDTO findById(Long id);
43
44 /**
45 *
46 * @param resources
47 */
48 void create(PointsAvailable resources);
49
50 /**
51 *
52 * @param resources
53 */
54 void update(PointsAvailable resources);
55
56 /**
57 *
58 * @param id
59 */
60 void delete(Long id);
61
62 /**
63 *
64 * @param id
65 */
66 void deleteBatchByIds(List<Long> id);
67
68 /**
69 * Code校验
70 * @param code
71 * @return PointsAvailableDTO
72 */
73 PointsAvailableDTO getByCode(String code);
74
75 /**
76 * 已过期的积分
77 * @param memberId
78 * @param timestamp
79 * @return
80 */
81 List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp);
82
83 /**
84 * 即将过期的积分
85 * @param memberId 会员id
86 * @param factor 阈值
87 * @return
88 */
89 Long findSoonExpireTime(Long memberId,Integer factor);
90
91 /**
92 * 查询数据分页
93 * @param criteria 条件参数
94 * @param pageable 分页参数
95 * @return Map<String,Object>
96 */
97 Map<String,Object> findByMemberIdAndExpireTimeBefore(PointsAvailableQueryCriteria criteria, Pageable pageable);
98
99 /**
100 *
101 * @param memberId
102 * @return
103 */
104 List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(Long memberId);
105
106 /**
107 * 可用总积分
108 * @param criteria 条件参数
109 * @return Map<String,Object>
110 */
111 Long findEveryDayPointsAvailable(PointsAvailableQueryCriteria criteria);
112
113 /**
114 * 总积分
115 * @param criteria
116 * @return
117 */
118 Long findEveryDayPointsProduce(PointsAvailableQueryCriteria criteria);
119
120 /**
121 * 积分消耗
122 * @param criteria
123 * @return
124 */
125 Long findEveryDayPointsConsume(PointsAvailableQueryCriteria criteria);
126
127 /**
128 * 积分过期
129 * @param criteria
130 * @return
131 */
132 Long findEveryDayPointsExpire(PointsAvailableQueryCriteria criteria);
133
134
135 long findAvailablePointsByMemberId(long memberId);
136
137
138 List<PointsAvailableDTO> findByExpireTimeBefore(Timestamp now);
139 }
1 package com.topdraw.business.basicdata.points.available.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-23
11 */
12 @Data
13 public class PointsAvailableDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 积分类型 0:通用型
22 private Integer pointsType;
23
24 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
25 private Integer deviceType;
26
27 // 会员id
28 private Long memberId;
29
30 // 积分值
31 private Long points;
32
33 // 过期时间
34 private Timestamp expireTime;
35
36 // 描述
37 private String description;
38
39 // 创建时间
40 private Timestamp createTime;
41
42 // 更新时间
43 private Timestamp updateTime;
44 }
1 package com.topdraw.business.basicdata.points.available.service.dto;
2
3 import lombok.Data;
4 import com.topdraw.annotation.Query;
5
6 import java.sql.Timestamp;
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-23
11 */
12 @Data
13 public class PointsAvailableQueryCriteria{
14
15 @Query
16 private Long memberId;
17
18 @Query
19 private Long accountId;
20
21 @Query(type = Query.Type.GREATER_THAN)
22 private Timestamp expireTime;
23
24 private PointsAvailableQueryType queryType;
25
26 }
1 package com.topdraw.business.basicdata.points.available.service.dto;
2
3 public enum PointsAvailableQueryType {
4
5 // 全部
6 ALL,
7 // 可用
8 AVAILABLE_ONLY
9
10 }
1 package com.topdraw.business.basicdata.points.available.service.impl;
2
3 import com.topdraw.business.basicdata.points.available.domain.PointsAvailable;
4 import com.topdraw.util.RedissonUtil;
5 import com.topdraw.util.TimestampUtil;
6 import com.topdraw.utils.ValidationUtil;
7 import com.topdraw.business.basicdata.points.available.repository.PointsAvailableRepository;
8 import com.topdraw.business.basicdata.points.available.service.PointsAvailableService;
9 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
10 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria;
11 import com.topdraw.business.basicdata.points.available.service.mapper.PointsAvailableMapper;
12 import org.redisson.api.RLock;
13 import org.redisson.api.RedissonClient;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Service;
16 import org.springframework.transaction.annotation.Propagation;
17 import org.springframework.transaction.annotation.Transactional;
18 import org.springframework.dao.EmptyResultDataAccessException;
19 import org.springframework.data.domain.Page;
20 import org.springframework.data.domain.Pageable;
21 import org.springframework.util.Assert;
22 import com.topdraw.utils.PageUtil;
23 import com.topdraw.utils.QueryHelp;
24 import com.topdraw.utils.StringUtils;
25
26 import java.sql.Timestamp;
27 import java.util.*;
28 import java.io.IOException;
29 import javax.servlet.http.HttpServletResponse;
30
31 /**
32 * @author XiangHan
33 * @date 2021-10-23
34 */
35 @Service
36 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
37 public class PointsAvailableServiceImpl implements PointsAvailableService {
38
39 @Autowired
40 private PointsAvailableRepository PointsAvailableRepository;
41
42 @Autowired
43 private PointsAvailableMapper PointsAvailableMapper;
44
45 @Autowired
46 private RedissonClient redissonClient;
47
48 @Override
49 public Map<String, Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable) {
50 Page<PointsAvailable> page = PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) ->
51 QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
52 return PageUtil.toPage(page.map(PointsAvailableMapper::toDto));
53 }
54
55 @Override
56 public Map<String, Object> findByMemberIdAndExpireTimeBefore(PointsAvailableQueryCriteria criteria, Pageable pageable) {
57 return this.queryAll(criteria,pageable);
58 }
59
60 @Override
61 public List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(Long memberId) {
62 return PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdOrderByExpireTime(memberId));
63 }
64
65 @Override
66 public List<PointsAvailableDTO> queryAll(PointsAvailableQueryCriteria criteria) {
67 return PointsAvailableMapper.toDto(PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
68 }
69
70 @Override
71 public PointsAvailableDTO findById(Long id) {
72 PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseGet(PointsAvailable::new);
73 ValidationUtil.isNull(PointsAvailable.getId(),"PointsAvailable","id",id);
74 return PointsAvailableMapper.toDto(PointsAvailable);
75 }
76
77 @Override
78 @Transactional(rollbackFor = Exception.class)
79 public void create(PointsAvailable resources) {
80 PointsAvailableRepository.save(resources);
81 }
82
83 @Override
84 @Transactional(rollbackFor = Exception.class)
85 public void update(PointsAvailable resources) {
86 RLock rLock = this.redissonClient.getLock("updatePointsAvailable"+resources.getId().toString());
87 try {
88 RedissonUtil.lock(rLock);
89 PointsAvailable PointsAvailable = PointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new);
90 ValidationUtil.isNull( PointsAvailable.getId(),"PointsAvailable","id",resources.getId());
91 PointsAvailable.copy(resources);
92 PointsAvailableRepository.save(PointsAvailable);
93 } catch (Exception e) {
94 e.printStackTrace();
95 throw e;
96 } finally {
97 RedissonUtil.unlock(rLock);
98 }
99 }
100
101 @Override
102 @Transactional(rollbackFor = Exception.class)
103 public void delete(Long id) {
104 Assert.notNull(id, "The given id must not be null!");
105 PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow(
106 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1));
107 PointsAvailableRepository.delete(PointsAvailable);
108 }
109
110 @Override
111 public void deleteBatchByIds(List<Long> id) {
112 PointsAvailableRepository.deleteBatchByIds(id);
113 }
114
115
116 @Override
117 public PointsAvailableDTO getByCode(String code) {
118 return StringUtils.isNotEmpty(code) ? PointsAvailableMapper.toDto(PointsAvailableRepository.findFirstByCode(code).orElseGet(PointsAvailable::new))
119 : new PointsAvailableDTO();
120 }
121
122 @Override
123 public List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp) {
124 return Objects.nonNull(memberId)?
125 PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp))
126 :null;
127 }
128
129 @Override
130 public Long findSoonExpireTime(Long memberId, Integer factor) {
131 return PointsAvailableRepository.findSoonExpireTime(memberId, factor);
132 }
133
134
135 @Override
136 public Long findEveryDayPointsAvailable(PointsAvailableQueryCriteria criteria) {
137 return PointsAvailableRepository.findEveryDayPointsAvailable(criteria);
138 }
139
140 @Override
141 public Long findEveryDayPointsProduce(PointsAvailableQueryCriteria criteria) {
142 return this.PointsAvailableRepository.findEveryDayPointsProduce(criteria);
143 }
144
145 @Override
146 public Long findEveryDayPointsConsume(PointsAvailableQueryCriteria criteria) {
147 return 0L;
148 }
149
150 @Override
151 public Long findEveryDayPointsExpire(PointsAvailableQueryCriteria criteria) {
152 return this.PointsAvailableRepository.findEveryDayPointsExpire(criteria);
153 }
154
155 @Override
156 public long findAvailablePointsByMemberId(long memberId) {
157 return this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId);
158 }
159
160 @Override
161 public List<PointsAvailableDTO> findByExpireTimeBefore(Timestamp now) {
162 return PointsAvailableMapper.toDto(this.PointsAvailableRepository.findByExpireTimeBefore(now));
163 }
164
165 }
1 package com.topdraw.business.basicdata.points.available.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.points.available.domain.PointsAvailable;
5 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-23
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface PointsAvailableMapper extends BaseMapper<PointsAvailableDTO, PointsAvailable> {
15
16 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_points_detail_history")
24 public class PointsDetailHistory implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 标识
33 @Column(name = "code", nullable = false)
34 private String code;
35
36 // 应用code
37 @Column(name = "app_code")
38 private String appCode;
39
40 // 会员id
41 @Column(name = "member_id", nullable = false)
42 private Long memberId;
43
44 // 账号id
45 @Column(name = "account_id")
46 private Long accountId;
47
48 // 原始积分
49 @Column(name = "original_points", nullable = false)
50 private Long originalPoints;
51
52 // 结果积分
53 @Column(name = "result_points", nullable = false)
54 private Long resultPoints;
55
56 // 积分变化,积分获得为正,积分消耗为负
57 @Column(name = "points", nullable = false)
58 private Long points;
59
60 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
61 @Column(name = "device_type", nullable = false)
62 private Integer deviceType;
63
64 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他
65 @Column(name = "evt_type", nullable = false)
66 private Integer evtType;
67
68 // 订单id(针对订购操作)
69 @Column(name = "order_id")
70 private Long orderId;
71
72 // 节目id(针对观影操作)
73 @Column(name = "media_id")
74 private Long mediaId;
75
76 // 活动id(针对参与活动)
77 @Column(name = "activity_id")
78 private Long activityId;
79
80 // 积分变化描述,用于管理侧显示
81 @Column(name = "description", nullable = false)
82 private String description;
83
84 // 创建时间
85 @CreatedDate
86 @Column(name = "create_time")
87 private Timestamp createTime;
88
89 // 更新时间
90 @LastModifiedDate
91 @Column(name = "update_time")
92 private Timestamp updateTime;
93
94 public void copy(PointsDetailHistory source){
95 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
96 }
97 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.repository;
2
3 import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface PointsDetailHistoryRepository extends JpaRepository<PointsDetailHistory, Long>, JpaSpecificationExecutor<PointsDetailHistory> {
14
15 Optional<PointsDetailHistory> findFirstByCode(String code);
16 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory;
6 import com.topdraw.business.basicdata.points.detail.detailhistory.service.PointsDetailHistoryService;
7 import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "PointsDetailHistory管理")
19 //@RestController
20 //@RequestMapping("/api/PointsDetailHistory")
21 public class PointsDetailHistoryController {
22
23 /*@Autowired
24 private PointsDetailHistoryService PointsDetailHistoryService;
25
26 @GetMapping
27 @ApiOperation("查询PointsDetailHistory")
28 public ResultInfo getPointsDetailHistorys(PointsDetailHistoryQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(PointsDetailHistoryService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有PointsDetailHistory")
34 public ResultInfo getPointsDetailHistorys(PointsDetailHistoryQueryCriteria criteria) {
35 return ResultInfo.success(PointsDetailHistoryService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增PointsDetailHistory")
41 public ResultInfo create(@Validated @RequestBody PointsDetailHistory resources) {
42 PointsDetailHistoryService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改PointsDetailHistory")
49 public ResultInfo update(@Validated @RequestBody PointsDetailHistory resources) {
50 PointsDetailHistoryService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除PointsDetailHistory")
58 public ResultInfo delete(@PathVariable Long id) {
59 PointsDetailHistoryService.delete(id);
60 return ResultInfo.success();
61 }
62
63 @GetMapping(value = "/getByCode/{code}")
64 @ApiOperation(value = "根据标识查询")
65 public ResultInfo getByCode(@PathVariable String code) {
66 return ResultInfo.success(PointsDetailHistoryService.getByCode(code));
67 }*/
68 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.service;
2
3 import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory;
4 import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO;
5 import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface PointsDetailHistoryService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(PointsDetailHistoryQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<PointsDetailHistoryDTO>
28 */
29 List<PointsDetailHistoryDTO> queryAll(PointsDetailHistoryQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return PointsDetailHistoryDTO
35 */
36 PointsDetailHistoryDTO findById(Long id);
37
38 void create(PointsDetailHistory resources);
39
40 void update(PointsDetailHistory resources);
41
42 void delete(Long id);
43
44 /**
45 * Code校验
46 * @param code
47 * @return PointsDetailHistoryDTO
48 */
49 PointsDetailHistoryDTO getByCode(String code);
50 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class PointsDetailHistoryDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 应用code
22 private String appCode;
23
24 // 会员id
25 private Long memberId;
26
27 // 账号id
28 private Long accountId;
29
30 // 原始积分
31 private Long originalPoints;
32
33 // 结果积分
34 private Long resultPoints;
35
36 // 积分变化,积分获得为正,积分消耗为负
37 private Long points;
38
39 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
40 private Integer deviceType;
41
42 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他
43 private Integer evtType;
44
45 // 订单id(针对订购操作)
46 private Long orderId;
47
48 // 节目id(针对观影操作)
49 private Long mediaId;
50
51 // 活动id(针对参与活动)
52 private Long activityId;
53
54 // 积分变化描述,用于管理侧显示
55 private String description;
56
57 // 创建时间
58 private Timestamp createTime;
59
60 // 更新时间
61 private Timestamp updateTime;
62 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class PointsDetailHistoryQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.points.detail.detailhistory.repository.PointsDetailHistoryRepository;
7 import com.topdraw.business.basicdata.points.detail.detailhistory.service.PointsDetailHistoryService;
8 import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO;
9 import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria;
10 import com.topdraw.business.basicdata.points.detail.detailhistory.service.mapper.PointsDetailHistoryMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21 import com.topdraw.utils.StringUtils;
22
23 import java.util.List;
24 import java.util.Map;
25
26 /**
27 * @author XiangHan
28 * @date 2021-10-22
29 */
30 @Service
31 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
32 public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryService {
33
34 @Autowired
35 private PointsDetailHistoryRepository PointsDetailHistoryRepository;
36
37 @Autowired
38 private PointsDetailHistoryMapper PointsDetailHistoryMapper;
39
40 @Override
41 public Map<String, Object> queryAll(PointsDetailHistoryQueryCriteria criteria, Pageable pageable) {
42 Page<PointsDetailHistory> page = PointsDetailHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
43 return PageUtil.toPage(page.map(PointsDetailHistoryMapper::toDto));
44 }
45
46 @Override
47 public List<PointsDetailHistoryDTO> queryAll(PointsDetailHistoryQueryCriteria criteria) {
48 return PointsDetailHistoryMapper.toDto(PointsDetailHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
49 }
50
51 @Override
52 public PointsDetailHistoryDTO findById(Long id) {
53 PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseGet(PointsDetailHistory::new);
54 ValidationUtil.isNull(PointsDetailHistory.getId(),"PointsDetailHistory","id",id);
55 return PointsDetailHistoryMapper.toDto(PointsDetailHistory);
56 }
57
58 @Override
59 @Transactional(rollbackFor = Exception.class)
60 @AsyncMqSend()
61 public void create(PointsDetailHistory resources) {
62 PointsDetailHistoryRepository.save(resources);
63 }
64
65 @Override
66 @Transactional(rollbackFor = Exception.class)
67 @AsyncMqSend()
68 public void update(PointsDetailHistory resources) {
69 PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(resources.getId()).orElseGet(PointsDetailHistory::new);
70 ValidationUtil.isNull( PointsDetailHistory.getId(),"PointsDetailHistory","id",resources.getId());
71 PointsDetailHistory.copy(resources);
72 PointsDetailHistoryRepository.save(PointsDetailHistory);
73 }
74
75 @Override
76 @Transactional(rollbackFor = Exception.class)
77 @AsyncMqSend()
78 public void delete(Long id) {
79 Assert.notNull(id, "The given id must not be null!");
80 PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseThrow(
81 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetailHistory.class, id), 1));
82 PointsDetailHistoryRepository.delete(PointsDetailHistory);
83 }
84
85
86 @Override
87 public PointsDetailHistoryDTO getByCode(String code) {
88 return StringUtils.isNotEmpty(code) ? PointsDetailHistoryMapper.toDto(PointsDetailHistoryRepository.findFirstByCode(code).orElseGet(PointsDetailHistory::new))
89 : new PointsDetailHistoryDTO();
90 }
91 }
1 package com.topdraw.business.basicdata.points.detail.detailhistory.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.points.detail.detailhistory.domain.PointsDetailHistory;
5 import com.topdraw.business.basicdata.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface PointsDetailHistoryMapper extends BaseMapper<PointsDetailHistoryDTO, PointsDetailHistory> {
15
16 }
1 package com.topdraw.business.basicdata.points.detail.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_points_detail")
24 public class PointsDetail implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 标识
33 @Column(name = "code", nullable = false)
34 private String code;
35
36 // 应用code
37 @Column(name = "app_code")
38 private String appCode;
39
40 // 会员id
41 @Column(name = "member_id", nullable = false)
42 private Long memberId;
43
44 // 账号id
45 @Column(name = "account_id")
46 private Long accountId;
47
48 // 原始积分
49 @Column(name = "original_points", nullable = false)
50 private Long originalPoints;
51
52 // 结果积分
53 @Column(name = "result_points", nullable = false)
54 private Long resultPoints;
55
56 // 积分变化,积分获得为正,积分消耗为负
57 @Column(name = "points", nullable = false)
58 private Long points;
59
60 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
61 @Column(name = "device_type", nullable = false)
62 private Integer deviceType;
63
64 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他
65 @Column(name = "evt_type", nullable = false)
66 private Integer evtType;
67
68 // 订单id(针对订购操作)
69 @Column(name = "order_id")
70 private Long orderId;
71
72 // 节目id(针对观影操作)
73 @Column(name = "media_id")
74 private Long mediaId;
75
76 // 活动id(针对参与活动)
77 @Column(name = "activity_id")
78 private Long activityId;
79
80 // 积分变化描述,用于管理侧显示
81 @Column(name = "description", nullable = false)
82 private String description;
83
84 // 创建时间
85 @CreatedDate
86 @Column(name = "create_time")
87 private Timestamp createTime;
88
89 // 更新时间
90 @LastModifiedDate
91 @Column(name = "update_time")
92 private Timestamp updateTime;
93
94 public void copy(PointsDetail source){
95 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
96 }
97 }
1 package com.topdraw.business.basicdata.points.detail.repository;
2
3 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Date;
8 import java.util.List;
9 import java.util.Optional;
10
11 /**
12 * @author XiangHan
13 * @date 2021-10-22
14 */
15 public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long>, JpaSpecificationExecutor<PointsDetail> {
16
17 Optional<PointsDetail> findFirstByCode(String code);
18
19 List<PointsDetail> findByMemberId(Long memberId);
20 }
1 package com.topdraw.business.basicdata.points.detail.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
6 import com.topdraw.business.basicdata.points.detail.service.PointsDetailService;
7 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "PointsDetail管理")
19 //@RestController
20 //@RequestMapping("/api/PointsDetail")
21 public class PointsDetailController {
22
23 /*@Autowired
24 private PointsDetailService PointsDetailService;
25
26 @GetMapping
27 @ApiOperation("查询PointsDetail")
28 public ResultInfo getPointsDetails(PointsDetailQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(PointsDetailService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有PointsDetail")
34 public ResultInfo getPointsDetails(PointsDetailQueryCriteria criteria) {
35 return ResultInfo.success(PointsDetailService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增PointsDetail")
41 public ResultInfo create(@Validated @RequestBody PointsDetail resources) {
42 PointsDetailService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改PointsDetail")
49 public ResultInfo update(@Validated @RequestBody PointsDetail resources) {
50 PointsDetailService.update(resources);
51 return ResultInfo.success();
52 }
53
54 @Log
55 @DeleteMapping(value = "/{id}")
56 @ApiOperation("删除PointsDetail")
57 public ResultInfo delete(@PathVariable Long id) {
58 PointsDetailService.delete(id);
59 return ResultInfo.success();
60 }
61
62 @GetMapping(value = "/getByCode/{code}")
63 @ApiOperation(value = "根据标识查询")
64 public ResultInfo getByCode(@PathVariable String code) {
65 return ResultInfo.success(PointsDetailService.getByCode(code));
66 }*/
67 }
1 package com.topdraw.business.basicdata.points.detail.service;
2
3 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
4 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
5 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailDTO;
6 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailQueryCriteria;
7 import org.springframework.data.domain.Pageable;
8
9 import java.util.Date;
10 import java.util.Map;
11 import java.util.List;
12
13 /**
14 * @author XiangHan
15 * @date 2021-10-22
16 */
17 public interface PointsDetailService {
18
19 /**
20 * 查询数据分页
21 * @param criteria 条件参数
22 * @param pageable 分页参数
23 * @return Map<String,Object>
24 */
25 Map<String,Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable);
26
27 /**
28 * 查询所有数据不分页
29 * @param criteria 条件参数
30 * @return List<PointsDetailDTO>
31 */
32 List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria);
33
34 /**
35 * 根据ID查询
36 * @param id ID
37 * @return PointsDetailDTO
38 */
39 PointsDetailDTO findById(Long id);
40
41 void create(PointsDetail resources);
42
43 void update(PointsDetail resources);
44
45 void delete(Long id);
46
47 /**
48 * Code校验
49 * @param code
50 * @return PointsDetailDTO
51 */
52 PointsDetailDTO getByCode(String code);
53
54 List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId);
55
56
57 /**
58 * 已过期的积分
59 * @param memberId
60 * @return
61 */
62 List<PointsDetailDTO> findByMemberId(Long memberId);
63 }
1 package com.topdraw.business.basicdata.points.detail.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class PointsDetailDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 应用code
22 private String appCode;
23
24 // 会员id
25 private Long memberId;
26
27 // 账号id
28 private Long accountId;
29
30 // 原始积分
31 private Long originalPoints;
32
33 // 结果积分
34 private Long resultPoints;
35
36 // 积分变化,积分获得为正,积分消耗为负
37 private Long points;
38
39 // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
40 private Integer deviceType;
41
42 // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他
43 private Integer evtType;
44
45 // 订单id(针对订购操作)
46 private Long orderId;
47
48 // 节目id(针对观影操作)
49 private Long mediaId;
50
51 // 活动id(针对参与活动)
52 private Long activityId;
53
54 // 积分变化描述,用于管理侧显示
55 private String description;
56
57 // 创建时间
58 private Timestamp createTime;
59
60 // 更新时间
61 private Timestamp updateTime;
62 }
1 package com.topdraw.business.basicdata.points.detail.service.dto;
2
3 import com.topdraw.annotation.Query;
4 import lombok.Data;
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-22
9 */
10 @Data
11 public class PointsDetailQueryCriteria{
12
13 @Query(type = Query.Type.EQUAL)
14 private Long memberId;
15
16 @Query(type = Query.Type.EQUAL)
17 private Long accountId;
18
19 }
1 package com.topdraw.business.basicdata.points.detail.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.points.detail.repository.PointsDetailRepository;
7 import com.topdraw.business.basicdata.points.detail.service.PointsDetailService;
8 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailDTO;
9 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailQueryCriteria;
10 import com.topdraw.business.basicdata.points.detail.service.mapper.PointsDetailMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21 import com.topdraw.utils.StringUtils;
22
23 import java.util.Date;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Objects;
27
28 /**
29 * @author XiangHan
30 * @date 2021-10-22
31 */
32 @Service
33 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
34 public class PointsDetailServiceImpl implements PointsDetailService {
35
36 @Autowired
37 private PointsDetailRepository PointsDetailRepository;
38
39 @Autowired
40 private PointsDetailMapper PointsDetailMapper;
41
42 @Override
43 public Map<String, Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable) {
44 Page<PointsDetail> page = PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
45 return PageUtil.toPage(page.map(PointsDetailMapper::toDto));
46 }
47
48 @Override
49 public List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria) {
50 return PointsDetailMapper.toDto(PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
51 }
52
53 @Override
54 public PointsDetailDTO findById(Long id) {
55 PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseGet(PointsDetail::new);
56 ValidationUtil.isNull(PointsDetail.getId(),"PointsDetail","id",id);
57 return PointsDetailMapper.toDto(PointsDetail);
58 }
59
60 @Override
61 @Transactional(rollbackFor = Exception.class)
62 @AsyncMqSend()
63 public void create(PointsDetail resources) {
64 PointsDetailRepository.save(resources);
65 }
66
67 @Override
68 @Transactional(rollbackFor = Exception.class)
69 @AsyncMqSend()
70 public void update(PointsDetail resources) {
71 PointsDetail PointsDetail = PointsDetailRepository.findById(resources.getId()).orElseGet(PointsDetail::new);
72 ValidationUtil.isNull( PointsDetail.getId(),"PointsDetail","id",resources.getId());
73 PointsDetail.copy(resources);
74 PointsDetailRepository.save(PointsDetail);
75 }
76
77 @Override
78 @Transactional(rollbackFor = Exception.class)
79 @AsyncMqSend()
80 public void delete(Long id) {
81 Assert.notNull(id, "The given id must not be null!");
82 PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseThrow(
83 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetail.class, id), 1));
84 PointsDetailRepository.delete(PointsDetail);
85 }
86
87
88 @Override
89 public PointsDetailDTO getByCode(String code) {
90 return StringUtils.isNotEmpty(code) ? PointsDetailMapper.toDto(PointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new))
91 : new PointsDetailDTO();
92 }
93
94 @Override
95 public List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId) {
96 return null;
97 }
98
99 @Override
100 public List<PointsDetailDTO> findByMemberId(Long memberId) {
101 return Objects.nonNull(memberId)?
102 PointsDetailMapper.toDto(PointsDetailRepository.findByMemberId(memberId))
103 :null;
104 }
105 }
1 package com.topdraw.business.basicdata.points.detail.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
5 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface PointsDetailMapper extends BaseMapper<PointsDetailDTO, PointsDetail> {
15
16 }
1 package com.topdraw.business.basicdata.points.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_points")
24 public class Points implements Serializable {
25
26 @Id
27 @Column(name = "id")
28 private Long id;
29
30 @Column(name = "user_id")
31 private Long userId;
32
33 // 积分类型,通用,绑定, 区分大小屏 todo
34 @Column(name = "point_type")
35 private Integer pointType;
36
37 // 绑定对应的实体, 如何描述?
38 @Column(name = "target_no")
39 private String targetNo;
40
41 // 本月期初积分值
42 @Column(name = "begin_points")
43 private Integer beginPoints;
44
45 // 当前积分余额
46 @Column(name = "current_points")
47 private Integer currentPoints;
48
49 // 本月到期积分
50 @Column(name = "expire_points")
51 private Integer expirePoints;
52
53 // 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)
54 @CreatedDate
55 @Column(name = "create_time")
56 private Timestamp createTime;
57
58 // 最后修改时间
59 @LastModifiedDate
60 @Column(name = "update_time")
61 private Timestamp updateTime;
62
63 public void copy(Points source){
64 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
65 }
66 }
1 package com.topdraw.business.basicdata.points.repository;
2
3 import com.topdraw.business.basicdata.points.domain.Points;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2021-10-22
10 */
11 public interface PointsRepository extends JpaRepository<Points, Long>, JpaSpecificationExecutor<Points> {
12
13 }
1 package com.topdraw.business.basicdata.points.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.points.domain.Points;
6 import com.topdraw.business.basicdata.points.service.PointsService;
7 import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "Points管理")
19 //@RestController
20 //@RequestMapping("/api/Points")
21 public class PointsController {
22
23 /* @Autowired
24 private PointsService PointsService;
25
26 @GetMapping
27 @ApiOperation("查询Points")
28 public ResultInfo getPointss(PointsQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(PointsService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有Points")
34 public ResultInfo getPointss(PointsQueryCriteria criteria) {
35 return ResultInfo.success(PointsService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增Points")
41 public ResultInfo create(@Validated @RequestBody Points resources) {
42 PointsService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改Points")
49 public ResultInfo update(@Validated @RequestBody Points resources) {
50 PointsService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除Points")
58 public ResultInfo delete(@PathVariable Long id) {
59 PointsService.delete(id);
60 return ResultInfo.success();
61 }*/
62
63 }
1 package com.topdraw.business.basicdata.points.service;
2
3 import com.topdraw.business.basicdata.points.domain.Points;
4 import com.topdraw.business.basicdata.points.service.dto.PointsDTO;
5 import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface PointsService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(PointsQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<PointsDTO>
28 */
29 List<PointsDTO> queryAll(PointsQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return PointsDTO
35 */
36 PointsDTO findById(Long id);
37
38 void create(Points resources);
39
40 void update(Points resources);
41
42 void delete(Long id);
43
44 }
1 package com.topdraw.business.basicdata.points.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
7 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 @Data
15 public class PointsDTO implements Serializable {
16
17 // 处理精度丢失问题
18 @JsonSerialize(using= ToStringSerializer.class)
19 private Long id;
20
21 private Long userId;
22
23 // 积分类型,通用,绑定, 区分大小屏 todo
24 private Integer pointType;
25
26 // 绑定对应的实体, 如何描述?
27 private String targetNo;
28
29 // 本月期初积分值
30 private Integer beginPoints;
31
32 // 当前积分余额
33 private Integer currentPoints;
34
35 // 本月到期积分
36 private Integer expirePoints;
37
38 // 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)
39 private Timestamp createTime;
40
41 // 最后修改时间
42 private Timestamp updateTime;
43 }
1 package com.topdraw.business.basicdata.points.service.dto;
2
3 import lombok.Data;
4
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-22
9 */
10 @Data
11 public class PointsQueryCriteria{
12
13 }
1 package com.topdraw.business.basicdata.points.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.points.domain.Points;
5 import com.topdraw.util.RedissonUtil;
6 import com.topdraw.utils.ValidationUtil;
7 import com.topdraw.business.basicdata.points.repository.PointsRepository;
8 import com.topdraw.business.basicdata.points.service.PointsService;
9 import com.topdraw.business.basicdata.points.service.dto.PointsDTO;
10 import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria;
11 import com.topdraw.business.basicdata.points.service.mapper.PointsMapper;
12 import org.redisson.api.RLock;
13 import org.redisson.api.RedissonClient;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Service;
16 import org.springframework.transaction.annotation.Propagation;
17 import org.springframework.transaction.annotation.Transactional;
18 import org.springframework.dao.EmptyResultDataAccessException;
19 import cn.hutool.core.lang.Snowflake;
20 import cn.hutool.core.util.IdUtil;
21 import org.springframework.data.domain.Page;
22 import org.springframework.data.domain.Pageable;
23 import org.springframework.util.Assert;
24 import com.topdraw.utils.PageUtil;
25 import com.topdraw.utils.QueryHelp;
26
27 import java.util.List;
28 import java.util.Map;
29
30 /**
31 * @author XiangHan
32 * @date 2021-10-22
33 */
34 @Service
35 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
36 public class PointsServiceImpl implements PointsService {
37
38 @Autowired
39 private PointsRepository PointsRepository;
40
41 @Autowired
42 private PointsMapper PointsMapper;
43
44 @Autowired
45 private RedissonClient redissonClient;
46
47 @Override
48 public Map<String, Object> queryAll(PointsQueryCriteria criteria, Pageable pageable) {
49 Page<Points> page = PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
50 return PageUtil.toPage(page.map(PointsMapper::toDto));
51 }
52
53 @Override
54 public List<PointsDTO> queryAll(PointsQueryCriteria criteria) {
55 return PointsMapper.toDto(PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
56 }
57
58 @Override
59 public PointsDTO findById(Long id) {
60 Points Points = PointsRepository.findById(id).orElseGet(Points::new);
61 ValidationUtil.isNull(Points.getId(),"Points","id",id);
62 return PointsMapper.toDto(Points);
63 }
64
65 @Override
66 @Transactional(rollbackFor = Exception.class)
67 @AsyncMqSend()
68 public void create(Points resources) {
69 Snowflake snowflake = IdUtil.createSnowflake(1, 1);
70 resources.setId(snowflake.nextId());
71 PointsRepository.save(resources);
72 }
73
74 @Override
75 @Transactional(rollbackFor = Exception.class)
76 @AsyncMqSend()
77 public void update(Points resources) {
78 RLock rLock = this.redissonClient.getLock(resources.getId().toString());
79 try {
80 RedissonUtil.lock(rLock);
81 Points Points = PointsRepository.findById(resources.getId()).orElseGet(Points::new);
82 ValidationUtil.isNull(Points.getId(), "Points", "id", resources.getId());
83 Points.copy(resources);
84 PointsRepository.save(Points);
85 } catch (Exception e) {
86 e.printStackTrace();
87 throw e;
88 } finally {
89 RedissonUtil.unlock(rLock);
90 }
91 }
92
93 @Override
94 @Transactional(rollbackFor = Exception.class)
95 @AsyncMqSend()
96 public void delete(Long id) {
97 Assert.notNull(id, "The given id must not be null!");
98 Points Points = PointsRepository.findById(id).orElseThrow(
99 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Points.class, id), 1));
100 PointsRepository.delete(Points);
101 }
102
103
104 }
1 package com.topdraw.business.basicdata.points.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.points.domain.Points;
5 import com.topdraw.business.basicdata.points.service.dto.PointsDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface PointsMapper extends BaseMapper<PointsDTO, Points> {
15
16 }
1 package com.topdraw.business.basicdata.points.standingbook.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-29
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_points_standing_book")
24 public class PointsStandingBook implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 积分生产
33 @Column(name = "points_produce", nullable = false)
34 private Long pointsProduce;
35
36 // 积分消耗
37 @Column(name = "points_consume", nullable = false)
38 private Long pointsConsume;
39
40 // 可用总积分
41 @Column(name = "points_available", nullable = false)
42 private Long pointsAvailable;
43
44 // 积分过期
45 @Column(name = "points_expire", nullable = false)
46 private Long pointsExpire;
47
48 // 日期
49 @Column(name = "day")
50 private String day;
51
52 // 创建时间
53 @CreatedDate
54 @Column(name = "create_time")
55 private Timestamp createTime;
56
57 // 创建时间
58 @LastModifiedDate
59 @Column(name = "update_time")
60 private Timestamp updateTime;
61
62 public void copy(PointsStandingBook source){
63 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
64 }
65 }
1 package com.topdraw.business.basicdata.points.standingbook.repository;
2
3 import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-29
12 */
13 public interface PointsStandingBookRepository extends JpaRepository<PointsStandingBook, Long>, JpaSpecificationExecutor<PointsStandingBook> {
14
15 }
1 package com.topdraw.business.basicdata.points.standingbook.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook;
6 import com.topdraw.business.basicdata.points.standingbook.service.PointsStandingBookService;
7 import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.http.HttpStatus;
11 import org.springframework.http.ResponseEntity;
12 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.*;
14 import io.swagger.annotations.*;
15 import java.io.IOException;
16 import javax.servlet.http.HttpServletResponse;
17
18 /**
19 * @author XiangHan
20 * @date 2021-10-29
21 */
22 @Api(tags = "PointsStandingBook管理")
23 @RestController
24 @RequestMapping("/api/PointsStandingBook")
25 public class PointsStandingBookController {
26
27 @Autowired
28 private PointsStandingBookService PointsStandingBookService;
29
30 @GetMapping
31 @ApiOperation("查询PointsStandingBook")
32 public ResultInfo getPointsStandingBooks(PointsStandingBookQueryCriteria criteria, Pageable pageable) {
33 return ResultInfo.successPage(PointsStandingBookService.queryAll(criteria,pageable));
34 }
35
36 @GetMapping(value = "/all")
37 @ApiOperation("查询所有PointsStandingBook")
38 public ResultInfo getPointsStandingBooks(PointsStandingBookQueryCriteria criteria) {
39 return ResultInfo.success(PointsStandingBookService.queryAll(criteria));
40 }
41
42 @Log
43 @PostMapping
44 @ApiOperation("新增PointsStandingBook")
45 public ResultInfo create(@Validated @RequestBody PointsStandingBook resources) {
46 PointsStandingBookService.create(resources);
47 return ResultInfo.success();
48 }
49
50 @Log
51 @PutMapping
52 @ApiOperation("修改PointsStandingBook")
53 public ResultInfo update(@Validated @RequestBody PointsStandingBook resources) {
54 PointsStandingBookService.update(resources);
55 return ResultInfo.success();
56 }
57
58
59 @Log
60 @DeleteMapping(value = "/{id}")
61 @ApiOperation("删除PointsStandingBook")
62 public ResultInfo delete(@PathVariable Long id) {
63 PointsStandingBookService.delete(id);
64 return ResultInfo.success();
65 }
66
67 }
1 package com.topdraw.business.basicdata.points.standingbook.service;
2
3 import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook;
4 import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookDTO;
5 import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9 import java.io.IOException;
10 import javax.servlet.http.HttpServletResponse;
11
12 /**
13 * @author XiangHan
14 * @date 2021-10-29
15 */
16 public interface PointsStandingBookService {
17
18 /**
19 * 查询数据分页
20 * @param criteria 条件参数
21 * @param pageable 分页参数
22 * @return Map<String,Object>
23 */
24 Map<String,Object> queryAll(PointsStandingBookQueryCriteria criteria, Pageable pageable);
25
26 /**
27 * 查询所有数据不分页
28 * @param criteria 条件参数
29 * @return List<PointsStandingBookDTO>
30 */
31 List<PointsStandingBookDTO> queryAll(PointsStandingBookQueryCriteria criteria);
32
33 /**
34 * 根据ID查询
35 * @param id ID
36 * @return PointsStandingBookDTO
37 */
38 PointsStandingBookDTO findById(Long id);
39
40 void create(PointsStandingBook resources);
41
42 void update(PointsStandingBook resources);
43
44 void delete(Long id);
45
46 }
1 package com.topdraw.business.basicdata.points.standingbook.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-29
11 */
12 @Data
13 public class PointsStandingBookDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 积分生产
19 private Long pointsProduce;
20
21 // 积分消耗
22 private Long pointsConsume;
23
24 // 可用总积分
25 private Long pointsAvailable;
26
27 // 积分过期
28 private Long pointsExpire;
29
30 // 日期
31 private String day;
32
33 // 创建时间
34 private Timestamp createTime;
35
36 // 创建时间
37 private Timestamp updateTime;
38 }
1 package com.topdraw.business.basicdata.points.standingbook.service.dto;
2
3 import lombok.Data;
4 import com.topdraw.annotation.Query;
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-29
9 */
10 @Data
11 public class PointsStandingBookQueryCriteria{
12 }
1 package com.topdraw.business.basicdata.points.standingbook.service.impl;
2
3 import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook;
4 import com.topdraw.utils.ValidationUtil;
5 import com.topdraw.utils.FileUtil;
6 import com.topdraw.business.basicdata.points.standingbook.repository.PointsStandingBookRepository;
7 import com.topdraw.business.basicdata.points.standingbook.service.PointsStandingBookService;
8 import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookDTO;
9 import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookQueryCriteria;
10 import com.topdraw.business.basicdata.points.standingbook.service.mapper.PointsStandingBookMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21 import com.topdraw.utils.StringUtils;
22
23 import java.util.List;
24 import java.util.Map;
25 import java.io.IOException;
26 import javax.servlet.http.HttpServletResponse;
27 import java.util.ArrayList;
28 import java.util.LinkedHashMap;
29
30 /**
31 * @author XiangHan
32 * @date 2021-10-29
33 */
34 @Service
35 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
36 public class PointsStandingBookServiceImpl implements PointsStandingBookService {
37
38 @Autowired
39 private PointsStandingBookRepository PointsStandingBookRepository;
40
41 @Autowired
42 private PointsStandingBookMapper PointsStandingBookMapper;
43
44 @Override
45 public Map<String, Object> queryAll(PointsStandingBookQueryCriteria criteria, Pageable pageable) {
46 Page<PointsStandingBook> page = PointsStandingBookRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
47 return PageUtil.toPage(page.map(PointsStandingBookMapper::toDto));
48 }
49
50 @Override
51 public List<PointsStandingBookDTO> queryAll(PointsStandingBookQueryCriteria criteria) {
52 return PointsStandingBookMapper.toDto(PointsStandingBookRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
53 }
54
55 @Override
56 public PointsStandingBookDTO findById(Long id) {
57 PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(id).orElseGet(PointsStandingBook::new);
58 ValidationUtil.isNull(PointsStandingBook.getId(),"PointsStandingBook","id",id);
59 return PointsStandingBookMapper.toDto(PointsStandingBook);
60 }
61
62 @Override
63 @Transactional(rollbackFor = Exception.class)
64 public void create(PointsStandingBook resources) {
65 PointsStandingBookRepository.save(resources);
66 }
67
68 @Override
69 @Transactional(rollbackFor = Exception.class)
70 public void update(PointsStandingBook resources) {
71 PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(resources.getId()).orElseGet(PointsStandingBook::new);
72 ValidationUtil.isNull( PointsStandingBook.getId(),"PointsStandingBook","id",resources.getId());
73 PointsStandingBook.copy(resources);
74 PointsStandingBookRepository.save(PointsStandingBook);
75 }
76
77 @Override
78 @Transactional(rollbackFor = Exception.class)
79 public void delete(Long id) {
80 Assert.notNull(id, "The given id must not be null!");
81 PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(id).orElseThrow(
82 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsStandingBook.class, id), 1));
83 PointsStandingBookRepository.delete(PointsStandingBook);
84 }
85
86
87 }
1 package com.topdraw.business.basicdata.points.standingbook.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook;
5 import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-29
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface PointsStandingBookMapper extends BaseMapper<PointsStandingBookDTO, PointsStandingBook> {
15
16 }
1 package com.topdraw.business.basicdata.rights.constant;
2
3 public class RightsType {
4
5 public static String TYPE_1 = "1";
6 Integer TYPE_2 = 2;
7 Integer TYPE_3 = 3;
8
9 }
1 package com.topdraw.business.basicdata.rights.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="tr_rights")
24 public class Rights implements Serializable {
25
26 // 主键
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 标识
33 @Column(name = "code", nullable = false)
34 private String code;
35
36 // 权益名称
37 // @Column(name = "name")
38 // private String name;
39
40 // 类型 1:实体类 (预留字段)
41 @Column(name = "type", nullable = false)
42 private Integer type;
43
44 // 终端类型 0:大屏;1:微信小程序/公众号;2:App
45 @Column(name = "device_type", nullable = false)
46 private Integer deviceType;
47
48 // 权益的实体类型 1:积分;2成长值;3优惠券
49 @Column(name = "entity_type", nullable = false)
50 private String entityType;
51
52 // 实体id
53 @Column(name = "entity_id", nullable = false)
54 private Long entityId;
55
56 // 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间
57 @Column(name = "valid_time")
58 private Timestamp validTime;
59
60 // 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数
61 @Column(name = "expire_time")
62 private Long expireTime;
63
64 // 创建时间
65 @CreatedDate
66 @Column(name = "create_time")
67 private Timestamp createTime;
68
69 // 更新时间
70 @LastModifiedDate
71 @Column(name = "update_time")
72 private Timestamp updateTime;
73
74 // 图片
75 @Column(name = "image")
76 private String image;
77
78 // 图片
79 @Column(name = "images")
80 private String images;
81
82 // 描述
83 @Column(name = "description")
84 private String description;
85
86 public void copy(Rights source){
87 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
88 }
89 }
1 package com.topdraw.business.basicdata.rights.history.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="tr_rights_histroy")
24 public class RightsHistory implements Serializable {
25
26 // 主键id
27 @Id
28 @GeneratedValue(strategy = GenerationType.IDENTITY)
29 @Column(name = "id")
30 private Long id;
31
32 // 权益id
33 @Column(name = "rights_id",nullable = false)
34 private Long rightsId;
35
36 // 会员id
37 @Column(name = "member_id",nullable = false)
38 private Long memberId;
39
40 @Transient
41 private Long userId;
42
43 // 操作者id(手动发放时保存)
44 @Column(name = "operator_id",nullable = false)
45 private Long operatorId;
46
47 // 操作者名称(手动发放时保存)
48 @Column(name = "operator_name",nullable = false)
49 private String operatorName;
50
51 // 发放时间
52 @Column(name = "send_time")
53 private Timestamp sendTime;
54
55 // 失效时间
56 @Column(name = "expire_time")
57 private Timestamp expireTime;
58
59 @CreatedDate
60 @Column(name = "create_time")
61 private Timestamp createTime;
62
63 @LastModifiedDate
64 @Column(name = "update_time")
65 private Timestamp updateTime;
66
67 public void copy(RightsHistory source){
68 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
69 }
70 }
1 package com.topdraw.business.basicdata.rights.history.repository;
2
3 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2021-10-22
10 */
11 public interface RightsHistoryRepository extends JpaRepository<RightsHistory, Long>, JpaSpecificationExecutor<RightsHistory> {
12
13 }
1 package com.topdraw.business.basicdata.rights.history.rest;
2
3 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryType;
4 import com.topdraw.common.ResultInfo;
5 import com.topdraw.annotation.Log;
6 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
7 import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService;
8 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria;
9 import com.topdraw.util.TimestampUtil;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.data.domain.Pageable;
12 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.*;
14 import io.swagger.annotations.*;
15
16 /**
17 * @author XiangHan
18 * @date 2021-10-22
19 */
20 @Api(tags = "RightsHistory管理")
21 @RestController
22 @RequestMapping("/api/RightsHistory")
23 public class RightsHistoryController {
24
25 @Autowired
26 private RightsHistoryService RightsHistoryService;
27
28 @GetMapping(value = "/pageRightsHistory")
29 @ApiOperation("查询RightsHistory")
30 public ResultInfo pageRightsHistory(RightsHistoryQueryCriteria criteria, Pageable pageable) {
31 return ResultInfo.successPage(RightsHistoryService.queryAll(criteria,pageable));
32 }
33
34 @GetMapping(value = "/pageAvailableRights")
35 @ApiOperation("查询用户可用权益列表")
36 public ResultInfo pageAvailableRights(RightsHistoryQueryCriteria criteria, Pageable pageable) {
37 criteria.setExpireTime(TimestampUtil.now());
38 return ResultInfo.successPage(RightsHistoryService.queryAll(criteria,pageable));
39 }
40
41 }
1 package com.topdraw.business.basicdata.rights.history.service;
2
3 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
4 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryDTO;
5 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface RightsHistoryService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<RightsHistoryDTO>
28 */
29 List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return RightsHistoryDTO
35 */
36 RightsHistoryDTO findById(Long id);
37
38 /**
39 *
40 * @param resources
41 */
42 void create(RightsHistory resources);
43
44 /**
45 *
46 * @param resources
47 */
48 void update(RightsHistory resources);
49
50 /**
51 *
52 * @param id
53 */
54 void delete(Long id);
55
56 }
1 package com.topdraw.business.basicdata.rights.history.service.dto;
2
3 import lombok.Data;
4
5 import javax.persistence.Column;
6 import java.sql.Timestamp;
7 import java.io.Serializable;
8
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 @Data
15 public class RightsHistoryDTO implements Serializable {
16
17 // 主键id
18 private Long id;
19
20 // 权益id
21 private Long rightsId;
22
23 // 会员id
24 private Long memberId;
25
26 // 操作者id(手动发放时保存)
27 private Long operatorId;
28
29 // 操作者名称(手动发放时保存)
30 private String operatorName;
31
32 // 发放时间
33 private Timestamp sendTime;
34
35 // 失效时间
36 private Timestamp expireTime;
37
38 private Timestamp createTime;
39
40 private Timestamp updateTime;
41 }
1 package com.topdraw.business.basicdata.rights.history.service.dto;
2
3 import com.topdraw.annotation.Query;
4 import lombok.Data;
5
6 import java.sql.Timestamp;
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class RightsHistoryQueryCriteria{
14
15 @Query
16 private Long memberId;
17
18 @Query(type = Query.Type.GREATER_THAN)
19 private Timestamp expireTime;
20
21 private RightsHistoryQueryType queryType;
22
23 }
1 package com.topdraw.business.basicdata.rights.history.service.dto;
2
3 public enum RightsHistoryQueryType {
4
5 // 全部
6 ALL,
7 // 可用
8 AVAILABLE_ONLY
9
10 }
1 package com.topdraw.business.basicdata.rights.history.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.rights.history.repository.RightsHistoryRepository;
7 import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService;
8 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryDTO;
9 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria;
10 import com.topdraw.business.basicdata.rights.history.service.mapper.RightsHistoryMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21
22 import java.util.List;
23 import java.util.Map;
24
25 /**
26 * @author XiangHan
27 * @date 2021-10-22
28 */
29 @Service
30 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
31 public class RightsHistoryServiceImpl implements RightsHistoryService {
32
33 @Autowired
34 private RightsHistoryRepository RightsHistoryRepository;
35
36 @Autowired
37 private RightsHistoryMapper RightsHistoryMapper;
38
39 @Override
40 public Map<String, Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable) {
41 Page<RightsHistory> page = RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
42 return PageUtil.toPage(page.map(RightsHistoryMapper::toDto));
43 }
44
45 @Override
46 public List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria) {
47 return RightsHistoryMapper.toDto(RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
48 }
49
50 @Override
51 public RightsHistoryDTO findById(Long id) {
52 RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseGet(RightsHistory::new);
53 ValidationUtil.isNull(RightsHistory.getId(),"RightsHistory","id",id);
54 return RightsHistoryMapper.toDto(RightsHistory);
55 }
56
57 @Override
58 @Transactional(rollbackFor = Exception.class)
59 @AsyncMqSend()
60 public void create(RightsHistory resources) {
61 RightsHistoryRepository.save(resources);
62 }
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 @AsyncMqSend()
67 public void update(RightsHistory resources) {
68 RightsHistory RightsHistory = RightsHistoryRepository.findById(resources.getId()).orElseGet(RightsHistory::new);
69 ValidationUtil.isNull( RightsHistory.getId(),"RightsHistory","id",resources.getId());
70 RightsHistory.copy(resources);
71 RightsHistoryRepository.save(RightsHistory);
72 }
73
74 @Override
75 @Transactional(rollbackFor = Exception.class)
76 @AsyncMqSend()
77 public void delete(Long id) {
78 Assert.notNull(id, "The given id must not be null!");
79 RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseThrow(
80 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", RightsHistory.class, id), 1));
81 RightsHistoryRepository.delete(RightsHistory);
82 }
83
84
85 }
1 package com.topdraw.business.basicdata.rights.history.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
5 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface RightsHistoryMapper extends BaseMapper<RightsHistoryDTO, RightsHistory> {
15
16 }
1 package com.topdraw.business.basicdata.rights.permanentrights.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12 import java.math.BigDecimal;
13
14 import java.io.Serializable;
15
16 /**
17 * @author XiangHan
18 * @date 2021-10-22
19 */
20 @Entity
21 @Data
22 @EntityListeners(AuditingEntityListener.class)
23 @Accessors(chain = true)
24 @Table(name="uc_permanent_rights")
25 public class PermanentRights implements Serializable {
26
27 // ID
28 @Id
29 @GeneratedValue(strategy = GenerationType.IDENTITY)
30 @Column(name = "id")
31 private Long id;
32
33 // 标识
34 @Column(name = "code", nullable = false)
35 private String code;
36
37 // 名称
38 @Column(name = "name", nullable = false)
39 private String name;
40
41 // 永久权益类型 0:vip;1:会员等级
42 @Column(name = "type")
43 private Integer type;
44
45 // 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index)
46 @Column(name = "level")
47 private Integer level;
48
49 // 商品折扣,10代表10% off,范围为0-100
50 @Column(name = "item_discount", nullable = false)
51 private BigDecimal itemDiscount;
52
53 // 额外积分比率,范围为0-1000
54 @Column(name = "extra_points", nullable = false)
55 private BigDecimal extraPoints;
56
57 // 免广告
58 @Column(name = "ad_disabled", nullable = false)
59 private Integer adDisabled;
60
61 // 额外活动参与机会
62 @Column(name = "extra_activity_ticket", nullable = false)
63 private Integer extraActivityTicket;
64
65 // 免费试看
66 @Column(name = "free_trial", nullable = false)
67 private Integer freeTrial;
68
69 // 上电视专区权益
70 @Column(name = "zone_sds", nullable = false)
71 private Integer zoneSds;
72
73 // 创建时间
74 @CreatedDate
75 @Column(name = "create_time")
76 private Timestamp createTime;
77
78 // 更新时间
79 @LastModifiedDate
80 @Column(name = "update_time")
81 private Timestamp updateTime;
82
83 public void copy(PermanentRights source){
84 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
85 }
86 }
1 package com.topdraw.business.basicdata.rights.permanentrights.repository;
2
3 import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> {
14
15 Optional<PermanentRights> findFirstByCode(String code);
16 }
1 package com.topdraw.business.basicdata.rights.permanentrights.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights;
6 import com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService;
7 import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "PermanentRights管理")
19 @RestController
20 @RequestMapping("/api/PermanentRights")
21 public class PermanentRightsController {
22
23 @Autowired
24 private PermanentRightsService PermanentRightsService;
25
26 @GetMapping
27 @ApiOperation("查询PermanentRights")
28 public ResultInfo pagePermanentRights(PermanentRightsQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(PermanentRightsService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/findById/{id}")
33 @ApiOperation("查询PermanentRights")
34 public ResultInfo findById(@PathVariable("id") Long id) {
35 return ResultInfo.success(PermanentRightsService.findById(id));
36 }
37
38 @Log
39 @PostMapping(value = "/create")
40 @ApiOperation("新增PermanentRights")
41 public ResultInfo create(@Validated @RequestBody PermanentRights resources) {
42 PermanentRightsService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping(value = "/update")
48 @ApiOperation("修改PermanentRights")
49 public ResultInfo update(@Validated @RequestBody PermanentRights resources) {
50 PermanentRightsService.update(resources);
51 return ResultInfo.success();
52 }
53
54 @Log
55 @DeleteMapping(value = "/delete/{id}")
56 @ApiOperation("删除PermanentRights")
57 public ResultInfo delete(@PathVariable Long id) {
58 PermanentRightsService.delete(id);
59 return ResultInfo.success();
60 }
61
62 @GetMapping(value = "/getByCode/{code}")
63 @ApiOperation(value = "根据标识查询")
64 public ResultInfo getByCode(@PathVariable String code) {
65 return ResultInfo.success(PermanentRightsService.getByCode(code));
66 }
67 }
1 package com.topdraw.business.basicdata.rights.permanentrights.service;
2
3 import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights;
4 import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO;
5 import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface PermanentRightsService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<PermanentRightsDTO>
28 */
29 List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return PermanentRightsDTO
35 */
36 PermanentRightsDTO findById(Long id);
37
38 void create(PermanentRights resources);
39
40 void update(PermanentRights resources);
41
42 void delete(Long id);
43
44 /**
45 * Code校验
46 * @param code
47 * @return PermanentRightsDTO
48 */
49 PermanentRightsDTO getByCode(String code);
50 }
1 package com.topdraw.business.basicdata.rights.permanentrights.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.math.BigDecimal;
6 import java.io.Serializable;
7
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Data
14 public class PermanentRightsDTO implements Serializable {
15
16 // ID
17 private Long id;
18
19 // 标识
20 private String code;
21
22 // 名称
23 private String name;
24
25 // 永久权益类型 0:vip;1:会员等级
26 private Integer type;
27
28 // 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index)
29 private Integer level;
30
31 // 商品折扣,10代表10% off,范围为0-100
32 private BigDecimal itemDiscount;
33
34 // 额外积分比率,范围为0-1000
35 private BigDecimal extraPoints;
36
37 // 免广告
38 private Integer adDisabled;
39
40 // 额外活动参与机会
41 private Integer extraActivityTicket;
42
43 // 免费试看
44 private Integer freeTrial;
45
46 // 上电视专区权益
47 private Integer zoneSds;
48
49 // 创建时间
50 private Timestamp createTime;
51
52 // 更新时间
53 private Timestamp updateTime;
54 }
1 package com.topdraw.business.basicdata.rights.permanentrights.service.dto;
2
3 import com.topdraw.annotation.Query;
4 import lombok.Data;
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-22
9 */
10 @Data
11 public class PermanentRightsQueryCriteria{
12
13 @Query(type = Query.Type.EQUAL)
14 private Integer level;
15
16 }
1 package com.topdraw.business.basicdata.rights.permanentrights.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.rights.permanentrights.repository.PermanentRightsRepository;
7 import com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService;
8 import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO;
9 import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsQueryCriteria;
10 import com.topdraw.business.basicdata.rights.permanentrights.service.mapper.PermanentRightsMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21 import com.topdraw.utils.StringUtils;
22
23 import java.util.List;
24 import java.util.Map;
25
26 /**
27 * @author XiangHan
28 * @date 2021-10-22
29 */
30 @Service
31 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
32 public class PermanentRightsServiceImpl implements PermanentRightsService {
33
34 @Autowired
35 private PermanentRightsRepository PermanentRightsRepository;
36
37 @Autowired
38 private PermanentRightsMapper PermanentRightsMapper;
39
40 @Override
41 public Map<String, Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable) {
42 Page<PermanentRights> page = PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
43 return PageUtil.toPage(page.map(PermanentRightsMapper::toDto));
44 }
45
46 @Override
47 public List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria) {
48 return PermanentRightsMapper.toDto(PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
49 }
50
51 @Override
52 public PermanentRightsDTO findById(Long id) {
53 PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseGet(PermanentRights::new);
54 ValidationUtil.isNull(PermanentRights.getId(),"PermanentRights","id",id);
55 return PermanentRightsMapper.toDto(PermanentRights);
56 }
57
58 @Override
59 @Transactional(rollbackFor = Exception.class)
60 // @AsyncMqSend()
61 public void create(PermanentRights resources) {
62 PermanentRightsRepository.save(resources);
63 }
64
65 @Override
66 @Transactional(rollbackFor = Exception.class)
67 // @AsyncMqSend()
68 public void update(PermanentRights resources) {
69 PermanentRights PermanentRights = PermanentRightsRepository.findById(resources.getId()).orElseGet(PermanentRights::new);
70 ValidationUtil.isNull( PermanentRights.getId(),"PermanentRights","id",resources.getId());
71 PermanentRights.copy(resources);
72 PermanentRightsRepository.save(PermanentRights);
73 }
74
75 @Override
76 @Transactional(rollbackFor = Exception.class)
77 public void delete(Long id) {
78 Assert.notNull(id, "The given id must not be null!");
79 PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseThrow(
80 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PermanentRights.class, id), 1));
81 PermanentRightsRepository.delete(PermanentRights);
82 }
83
84
85 @Override
86 public PermanentRightsDTO getByCode(String code) {
87 return StringUtils.isNotEmpty(code) ? PermanentRightsMapper.toDto(PermanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new))
88 : new PermanentRightsDTO();
89 }
90 }
1 package com.topdraw.business.basicdata.rights.permanentrights.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.rights.permanentrights.domain.PermanentRights;
5 import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface PermanentRightsMapper extends BaseMapper<PermanentRightsDTO, PermanentRights> {
15
16 }
1 package com.topdraw.business.basicdata.rights.repository;
2
3 import com.topdraw.business.basicdata.rights.domain.Rights;
4 import com.topdraw.business.basicdata.rights.service.dto.RightsDTO;
5 import org.springframework.data.jpa.repository.JpaRepository;
6 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
7 import org.springframework.data.jpa.repository.Query;
8
9 import java.util.List;
10 import java.util.Optional;
11
12 /**
13 * @author XiangHan
14 * @date 2021-10-22
15 */
16 public interface RightsRepository extends JpaRepository<Rights, Long>, JpaSpecificationExecutor<Rights> {
17
18 Optional<Rights> findFirstByCode(String code);
19
20 @Query(value = "FROM Rights r WHERE r.id IN (?2)",nativeQuery = false)
21 List<Rights> findBatchByIds(Long[] ids);
22 }
1 package com.topdraw.business.basicdata.rights.rest;
2
3 import com.topdraw.business.basicdata.rights.service.RightsService;
4 import com.topdraw.business.basicdata.rights.service.dto.RightsQueryCriteria;
5 import com.topdraw.common.ResultInfo;
6 import io.swagger.annotations.Api;
7 import io.swagger.annotations.ApiOperation;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.web.bind.annotation.GetMapping;
11 import org.springframework.web.bind.annotation.PathVariable;
12 import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.bind.annotation.RestController;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Api(tags = "Rights管理")
20 @RestController
21 @RequestMapping("/api/Rights")
22 public class RightsController {
23
24 @Autowired
25 private RightsService rightsService;
26
27 @GetMapping(value = "/findById/{id}")
28 @ApiOperation("查询Rights")
29 public ResultInfo findById(@PathVariable("id") Long id) {
30 return ResultInfo.success(rightsService.findById(id));
31 }
32
33 }
1 package com.topdraw.business.basicdata.rights.service;
2
3 import com.topdraw.business.basicdata.rights.domain.Rights;
4 import com.topdraw.business.basicdata.rights.service.dto.RightsDTO;
5 import com.topdraw.business.basicdata.rights.service.dto.RightsQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface RightsService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(RightsQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<RightsDTO>
28 */
29 List<RightsDTO> queryAll(RightsQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return RightsDTO
35 */
36 RightsDTO findById(Long id);
37
38 /**
39 * 批量查询
40 * @param ids
41 * @return
42 */
43 List<RightsDTO> findBatchByIds(Long... ids);
44
45 void create(Rights resources);
46
47 void update(Rights resources);
48
49 void delete(Long id);
50
51 /**
52 * Code校验
53 * @param code
54 * @return RightsDTO
55 */
56 RightsDTO getByCode(String code);
57 }
1 package com.topdraw.business.basicdata.rights.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class RightsDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 权益名称
22 // private String name;
23 // 终端类型 0:大屏;1:微信小程序/公众号;2:App
24 private Integer deviceType;
25
26 // 类型 1:实体类 (预留字段)
27 private Integer type;
28
29 // 权益的实体类型 1:积分;2成长值;3优惠券
30 private String entityType;
31
32 // 实体id
33 private Long entityId;
34
35 // 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间
36 private Timestamp validTime;
37
38 // 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数
39 private Long expireTime;
40
41 // 创建时间
42 private Timestamp createTime;
43
44 // 更新时间
45 private Timestamp updateTime;
46
47 // 图片
48 private String image;
49
50 // 图片
51 private String images;
52
53 // 描述
54 private String description;
55 }
1 package com.topdraw.business.basicdata.rights.service.dto;
2
3 import com.topdraw.annotation.Query;
4 import lombok.Data;
5
6 /**
7 * @author XiangHan
8 * @date 2021-10-22
9 */
10 @Data
11 public class RightsQueryCriteria{
12
13 @Query
14 private Long memberId;
15
16 private RightsQueryType queryType;
17
18 }
1 package com.topdraw.business.basicdata.rights.service.dto;
2
3 public enum RightsQueryType {
4
5 // 全部
6 ALL,
7 // 可用
8 AVAILABLE_ONLY
9
10 }
1 package com.topdraw.business.basicdata.rights.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.basicdata.rights.domain.Rights;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.rights.repository.RightsRepository;
7 import com.topdraw.business.basicdata.rights.service.RightsService;
8 import com.topdraw.business.basicdata.rights.service.dto.RightsDTO;
9 import com.topdraw.business.basicdata.rights.service.dto.RightsQueryCriteria;
10 import com.topdraw.business.basicdata.rights.service.mapper.RightsMapper;
11 import org.redisson.api.RLock;
12 import org.redisson.api.RedissonClient;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service;
15 import org.springframework.transaction.annotation.Propagation;
16 import org.springframework.transaction.annotation.Transactional;
17 import org.springframework.dao.EmptyResultDataAccessException;
18 import org.springframework.data.domain.Page;
19 import org.springframework.data.domain.Pageable;
20 import org.springframework.util.Assert;
21 import com.topdraw.utils.PageUtil;
22 import com.topdraw.utils.QueryHelp;
23 import com.topdraw.utils.StringUtils;
24 import org.springframework.util.CollectionUtils;
25
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30 * @author XiangHan
31 * @date 2021-10-22
32 */
33 @Service
34 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
35 public class RightsServiceImpl implements RightsService {
36
37 @Autowired
38 private RightsRepository RightsRepository;
39
40 @Autowired
41 private RightsMapper RightsMapper;
42
43 @Autowired
44 private RedissonClient redissonClient;
45
46 @Override
47 public Map<String, Object> queryAll(RightsQueryCriteria criteria, Pageable pageable) {
48 Page<Rights> page = RightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
49 return PageUtil.toPage(page.map(RightsMapper::toDto));
50 }
51
52 @Override
53 public List<RightsDTO> queryAll(RightsQueryCriteria criteria) {
54 return RightsMapper.toDto(RightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
55 }
56
57 @Override
58 public RightsDTO findById(Long id) {
59 Rights Rights = RightsRepository.findById(id).orElseGet(Rights::new);
60 ValidationUtil.isNull(Rights.getId(),"Rights","id",id);
61 return RightsMapper.toDto(Rights);
62 }
63
64 @Override
65 public List<RightsDTO> findBatchByIds(Long... ids) {
66 List<Rights> rightsList = this.RightsRepository.findBatchByIds(ids);
67 return !CollectionUtils.isEmpty(rightsList) ? RightsMapper.toDto(rightsList) : null;
68 }
69
70 @Override
71 @Transactional(rollbackFor = Exception.class)
72 @AsyncMqSend()
73 public void create(Rights resources) {
74 RightsRepository.save(resources);
75 }
76
77 @Override
78 @Transactional(rollbackFor = Exception.class)
79 @AsyncMqSend()
80 public void update(Rights resources) {
81 RLock rLock = this.redissonClient.getLock(resources.getId().toString());
82 try {
83 Rights Rights = RightsRepository.findById(resources.getId()).orElseGet(Rights::new);
84 ValidationUtil.isNull( Rights.getId(),"Rights","id",resources.getId());
85 Rights.copy(resources);
86 RightsRepository.save(Rights);
87 } catch (Exception e) {
88 e.printStackTrace();
89 throw e;
90 } finally {
91 rLock.unlock();
92 }
93 }
94
95 @Override
96 @Transactional(rollbackFor = Exception.class)
97 @AsyncMqSend()
98 public void delete(Long id) {
99 Assert.notNull(id, "The given id must not be null!");
100 Rights Rights = RightsRepository.findById(id).orElseThrow(
101 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Rights.class, id), 1));
102 RightsRepository.delete(Rights);
103 }
104
105
106 @Override
107 public RightsDTO getByCode(String code) {
108 return StringUtils.isNotEmpty(code) ? RightsMapper.toDto(RightsRepository.findFirstByCode(code).orElseGet(Rights::new))
109 : new RightsDTO();
110 }
111 }
1 package com.topdraw.business.basicdata.rights.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.rights.domain.Rights;
5 import com.topdraw.business.basicdata.rights.service.dto.RightsDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface RightsMapper extends BaseMapper<RightsDTO, Rights> {
15
16 }
1 package com.topdraw.business.basicdata.task.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="tr_task")
24 public class Task implements Serializable {
25
26 @Id
27 @GeneratedValue(strategy = GenerationType.IDENTITY)
28 @Column(name = "id")
29 private Long id;
30
31 // 任务模板id
32 @Column(name = "task_template_id", nullable = false)
33 private Long taskTemplateId;
34
35 // 任务重复类型,-1:不限次;1:单次;>1:多次
36 @Column(name = "task_repeat_type", nullable = false)
37 private Integer taskRepeatType;
38
39 // 任务每日重置 0:不重置;1:重置
40 @Column(name = "task_daily_reset", nullable = false)
41 private Integer taskDailyReset;
42
43 // 行为量(完成此任务需要多少次相同行为的触发)
44 @Column(name = "action_amount", nullable = false)
45 private Integer actionAmount;
46
47 // 任务生效时间
48 @Column(name = "valid_time")
49 private Timestamp validTime;
50
51 // 任务失效时间
52 @Column(name = "expire_time")
53 private Timestamp expireTime;
54
55 // 显示顺序
56 @Column(name = "sequence")
57 private Integer sequence;
58
59 // 获得成长值
60 @Column(name = "reward_exp", nullable = false)
61 private Long rewardExp;
62
63 // 获得积分
64 @Column(name = "reward_points", nullable = false)
65 private Long rewardPoints;
66
67 // 积分过期时间(空为不过期)
68 @Column(name = "reward_points_expire_time")
69 private Long rewardPointsExpireTime;
70
71 // 积分获取类型 0:定值;1:随机
72 @Column(name = "points_type")
73 private Integer pointsType;
74
75 // 随机积分最大值
76 @Column(name = "reward_max_points")
77 private Integer rewardMaxPoints;
78
79 // 能够获取该任务的用户分组,为空则都能获取
80 @Column(name = "groups")
81 private String groups;
82
83 // 权益发放策略 0:立即发放;1:次日发放;2:次月发放
84 @Column(name = "rights_send_strategy", nullable = false)
85 private Integer rightsSendStrategy;
86
87 // 会员等级门槛(0表示无门槛)
88 @Column(name = "member_level", nullable = false)
89 private Integer memberLevel;
90
91 // 会员vip门槛(0表示没有门槛)
92 @Column(name = "member_vip")
93 private Integer memberVip;
94
95 // 权益id
96 @Column(name = "rights_id")
97 private Long rightsId;
98
99 // 权益数量(活动机会次数、优惠券数量、奖品数量)
100 @Column(name = "rights_amount")
101 private Integer rightsAmount;
102
103 // 权益2id
104 @Column(name = "rights2_id")
105 private Long rights2Id;
106
107 // 权益2数量
108 @Column(name = "rights2_amount")
109 private Integer rights2Amount;
110
111 // 权益3id
112 @Column(name = "rights3_id")
113 private Long rights3Id;
114
115 // 权益3数量
116 @Column(name = "rights3_amount")
117 private Integer rights3Amount;
118
119 // 状态 0:失效;1:生效
120 @Column(name = "status", nullable = false)
121 private Integer status;
122
123 // 创建时间
124 @CreatedDate
125 @Column(name = "create_time")
126 private Timestamp createTime;
127
128 // 更新时间
129 @LastModifiedDate
130 @Column(name = "update_time")
131 private Timestamp updateTime;
132
133 public void copy(Task source){
134 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
135 }
136 }
1 package com.topdraw.business.basicdata.task.progress.domain;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
6 import lombok.experimental.Accessors;
7 import cn.hutool.core.bean.BeanUtil;
8 import cn.hutool.core.bean.copier.CopyOptions;
9 import javax.persistence.*;
10 import org.springframework.data.annotation.CreatedDate;
11 import org.springframework.data.annotation.LastModifiedDate;
12 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
13 import java.sql.Timestamp;
14
15 import java.io.Serializable;
16
17 /**
18 * @author XiangHan
19 * @date 2021-11-02
20 */
21 @Entity
22 @Data
23 @EntityListeners(AuditingEntityListener.class)
24 @Accessors(chain = true)
25 @Table(name="uc_tr_task_progress")
26 @AllArgsConstructor
27 @NoArgsConstructor
28 public class TrTaskProgress implements Serializable {
29
30 @Id
31 @GeneratedValue(strategy = GenerationType.IDENTITY)
32 @Column(name = "id")
33 private Long id;
34
35 // 用户id
36 @Column(name = "member_id", nullable = false)
37 private Long memberId;
38
39 // 任务id
40 @Column(name = "task_id")
41 private Long taskId;
42
43 // 已完成的行为量
44 @Column(name = "current_action_amount")
45 private Integer currentActionAmount;
46
47 // 目标行为量
48 @Column(name = "target_action_amount")
49 private Integer targetActionAmount;
50
51 // 状态 0:未完成;1:已完成
52 @Column(name = "status")
53 private Integer status;
54
55 // 完成时间
56 @Column(name = "completion_time")
57 private Timestamp completionTime;
58
59 @CreatedDate
60 @Column(name = "create_time")
61 private Timestamp createTime;
62
63 @LastModifiedDate
64 @Column(name = "update_time")
65 private Timestamp updateTime;
66
67 public void copy(TrTaskProgress source){
68 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
69 }
70 }
1 package com.topdraw.business.basicdata.task.progress.repository;
2
3 import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-11-02
12 */
13 public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> {
14
15 }
1 package com.topdraw.business.basicdata.task.progress.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress;
6 import com.topdraw.business.basicdata.task.progress.service.TrTaskProgressService;
7 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.http.HttpStatus;
11 import org.springframework.http.ResponseEntity;
12 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.*;
14 import io.swagger.annotations.*;
15 import java.io.IOException;
16 import javax.servlet.http.HttpServletResponse;
17
18 /**
19 * @author XiangHan
20 * @date 2021-11-02
21 */
22 @Api(tags = "TrTaskProgress管理")
23 @RestController
24 @RequestMapping("/api/TrTaskProgress")
25 public class TrTaskProgressController {
26
27 @Autowired
28 private TrTaskProgressService TrTaskProgressService;
29
30 @GetMapping
31 @ApiOperation("查询TrTaskProgress")
32 public ResultInfo getTrTaskProgresss(TrTaskProgressQueryCriteria criteria, Pageable pageable) {
33 return ResultInfo.successPage(TrTaskProgressService.queryAll(criteria,pageable));
34 }
35
36 @GetMapping(value = "/all")
37 @ApiOperation("查询所有TrTaskProgress")
38 public ResultInfo getTrTaskProgresss(TrTaskProgressQueryCriteria criteria) {
39 return ResultInfo.success(TrTaskProgressService.queryAll(criteria));
40 }
41
42 @Log
43 @PostMapping
44 @ApiOperation("新增TrTaskProgress")
45 public ResultInfo create(@Validated @RequestBody TrTaskProgress resources) {
46 TrTaskProgressService.create(resources);
47 return ResultInfo.success();
48 }
49
50 @Log
51 @PutMapping
52 @ApiOperation("修改TrTaskProgress")
53 public ResultInfo update(@Validated @RequestBody TrTaskProgress resources) {
54 TrTaskProgressService.update(resources);
55 return ResultInfo.success();
56 }
57
58
59 @Log
60 @DeleteMapping(value = "/{id}")
61 @ApiOperation("删除TrTaskProgress")
62 public ResultInfo delete(@PathVariable Long id) {
63 TrTaskProgressService.delete(id);
64 return ResultInfo.success();
65 }
66
67 }
1 package com.topdraw.business.basicdata.task.progress.service;
2
3 import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress;
4 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO;
5 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9 import java.io.IOException;
10 import javax.servlet.http.HttpServletResponse;
11
12 /**
13 * @author XiangHan
14 * @date 2021-11-02
15 */
16 public interface TrTaskProgressService {
17
18 /**
19 * 查询数据分页
20 * @param criteria 条件参数
21 * @param pageable 分页参数
22 * @return Map<String,Object>
23 */
24 Map<String,Object> queryAll(TrTaskProgressQueryCriteria criteria, Pageable pageable);
25
26 /**
27 * 查询所有数据不分页
28 * @param criteria 条件参数
29 * @return List<TrTaskProgressDTO>
30 */
31 List<TrTaskProgressDTO> queryAll(TrTaskProgressQueryCriteria criteria);
32
33 /**
34 * 根据ID查询
35 * @param id ID
36 * @return TrTaskProgressDTO
37 */
38 TrTaskProgressDTO findById(Long id);
39
40 void create(TrTaskProgress resources);
41
42 void update(TrTaskProgress resources);
43
44 void delete(Long id);
45
46 }
1 package com.topdraw.business.basicdata.task.progress.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-11-02
11 */
12 @Data
13 public class TrTaskProgressDTO implements Serializable {
14
15 private Long id;
16
17 // 用户id
18 private Long memberId;
19
20 // 任务id
21 private Long taskId;
22
23 // 已完成的行为量
24 private Integer currentActionAmount;
25
26 // 目标行为量
27 private Integer targetActionAmount;
28
29 // 状态 0:未完成;1:已完成
30 private Integer status;
31
32 // 完成时间
33 private Timestamp completionTime;
34
35 private Timestamp createTime;
36
37 private Timestamp updateTime;
38 }
1 package com.topdraw.business.basicdata.task.progress.service.dto;
2
3 import lombok.Data;
4 import com.topdraw.annotation.Query;
5
6 import java.sql.Timestamp;
7
8 /**
9 * @author XiangHan
10 * @date 2021-11-02
11 */
12 @Data
13 public class TrTaskProgressQueryCriteria{
14
15 @Query(type = Query.Type.EQUAL)
16 private Long taskId;
17
18 @Query(type = Query.Type.EQUAL)
19 private Long memberId;
20
21 @Query(type = Query.Type.BETWEEN)
22 private String completionTime;
23
24 }
1 package com.topdraw.business.basicdata.task.progress.service.impl;
2
3 import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress;
4 import com.topdraw.utils.ValidationUtil;
5 import com.topdraw.utils.FileUtil;
6 import com.topdraw.business.basicdata.task.progress.repository.TrTaskProgressRepository;
7 import com.topdraw.business.basicdata.task.progress.service.TrTaskProgressService;
8 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO;
9 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressQueryCriteria;
10 import com.topdraw.business.basicdata.task.progress.service.mapper.TrTaskProgressMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21 import com.topdraw.utils.StringUtils;
22
23 import java.util.List;
24 import java.util.Map;
25 import java.io.IOException;
26 import javax.servlet.http.HttpServletResponse;
27 import java.util.ArrayList;
28 import java.util.LinkedHashMap;
29
30 /**
31 * @author XiangHan
32 * @date 2021-11-02
33 */
34 @Service
35 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
36 public class TrTaskProgressServiceImpl implements TrTaskProgressService {
37
38 @Autowired
39 private TrTaskProgressRepository TrTaskProgressRepository;
40
41 @Autowired
42 private TrTaskProgressMapper TrTaskProgressMapper;
43
44 @Override
45 public Map<String, Object> queryAll(TrTaskProgressQueryCriteria criteria, Pageable pageable) {
46 Page<TrTaskProgress> page = TrTaskProgressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
47 return PageUtil.toPage(page.map(TrTaskProgressMapper::toDto));
48 }
49
50 @Override
51 public List<TrTaskProgressDTO> queryAll(TrTaskProgressQueryCriteria criteria) {
52 return TrTaskProgressMapper.toDto(TrTaskProgressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
53 }
54
55 @Override
56 public TrTaskProgressDTO findById(Long id) {
57 TrTaskProgress TrTaskProgress = TrTaskProgressRepository.findById(id).orElseGet(TrTaskProgress::new);
58 ValidationUtil.isNull(TrTaskProgress.getId(),"TrTaskProgress","id",id);
59 return TrTaskProgressMapper.toDto(TrTaskProgress);
60 }
61
62 @Override
63 @Transactional(rollbackFor = Exception.class)
64 public void create(TrTaskProgress resources) {
65 TrTaskProgressRepository.save(resources);
66 }
67
68 @Override
69 @Transactional(rollbackFor = Exception.class)
70 public void update(TrTaskProgress resources) {
71 TrTaskProgress TrTaskProgress = TrTaskProgressRepository.findById(resources.getId()).orElseGet(TrTaskProgress::new);
72 ValidationUtil.isNull( TrTaskProgress.getId(),"TrTaskProgress","id",resources.getId());
73 TrTaskProgress.copy(resources);
74 TrTaskProgressRepository.save(TrTaskProgress);
75 }
76
77 @Override
78 @Transactional(rollbackFor = Exception.class)
79 public void delete(Long id) {
80 Assert.notNull(id, "The given id must not be null!");
81 TrTaskProgress TrTaskProgress = TrTaskProgressRepository.findById(id).orElseThrow(
82 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", TrTaskProgress.class, id), 1));
83 TrTaskProgressRepository.delete(TrTaskProgress);
84 }
85
86
87 }
1 package com.topdraw.business.basicdata.task.progress.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress;
5 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-11-02
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface TrTaskProgressMapper extends BaseMapper<TrTaskProgressDTO, TrTaskProgress> {
15
16 }
1 package com.topdraw.business.basicdata.task.repository;
2
3 import com.topdraw.business.basicdata.task.domain.Task;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.List;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificationExecutor<Task> {
14
15 List<Task> findByTaskTemplateId(Long taskTemplateId);
16
17 // List<Task> findByTemplateId(Long taskTemplateId);
18 }
1 package com.topdraw.business.basicdata.task.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.task.domain.Task;
6 import com.topdraw.business.basicdata.task.service.TaskService;
7 import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "Task管理")
19 @RestController
20 @RequestMapping("/api/Task")
21 public class TaskController {
22
23 @Autowired
24 private TaskService TaskService;
25
26 @GetMapping
27 @ApiOperation("查询Task")
28 public ResultInfo getTasks(TaskQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(TaskService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有Task")
34 public ResultInfo getTasks(TaskQueryCriteria criteria) {
35 return ResultInfo.success(TaskService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增Task")
41 public ResultInfo create(@Validated @RequestBody Task resources) {
42 TaskService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改Task")
49 public ResultInfo update(@Validated @RequestBody Task resources) {
50 TaskService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除Task")
58 public ResultInfo delete(@PathVariable Long id) {
59 TaskService.delete(id);
60 return ResultInfo.success();
61 }
62
63 }
1 package com.topdraw.business.basicdata.task.service;
2
3 import com.topdraw.business.basicdata.task.domain.Task;
4 import com.topdraw.business.basicdata.task.service.dto.TaskDTO;
5 import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface TaskService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(TaskQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<TaskDTO>
28 */
29 List<TaskDTO> queryAll(TaskQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return TaskDTO
35 */
36 TaskDTO findById(Long id);
37
38 void create(Task resources);
39
40 void update(Task resources);
41
42 void delete(Long id);
43
44 List<Task> findByTemplateId(Long taskTemplateId);
45 }
1 package com.topdraw.business.basicdata.task.service.dto;
2
3 import lombok.Data;
4
5 import javax.persistence.Column;
6 import java.sql.Timestamp;
7 import java.io.Serializable;
8
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 @Data
15 public class TaskDTO implements Serializable {
16
17 private Long id;
18
19 // 任务模板id
20 private Long taskTemplateId;
21
22 // 任务重复类型,-1:不限次;1:单次;>1:多次
23 private Integer taskRepeatType;
24
25 // 任务每日重置 0:不重置;1:重置
26 private Integer taskDailyReset;
27
28 // 行为量(完成此任务需要多少次相同行为的触发)
29 private Integer actionAmount;
30
31 // 任务生效时间
32 private Timestamp validTime;
33
34 // 任务失效时间
35 private Timestamp expireTime;
36
37 // 显示顺序
38 private Integer sequence;
39
40 // 获得成长值
41 private Long rewardExp;
42
43 // 获得积分
44 private Long rewardPoints;
45
46 // 积分过期时间(空为不过期)
47 private Long rewardPointsExpireTime;
48
49 // 能够获取该任务的用户分组,为空则都能获取
50 private String groups;
51
52 // 会员等级门槛(0表示无门槛)
53 private Integer memberLevel;
54
55 // 会员vip门槛(0表示没有门槛)
56 private Integer memberVip;
57
58 // 权益id
59 private Long rightsId;
60
61 // 权益数量(活动机会次数、优惠券数量、奖品数量)
62 private Integer rightsAmount;
63
64 // 权益2id
65 private Long rights2Id;
66
67 // 权益2数量
68 private Integer rights2Amount;
69
70 // 权益3id
71 private Long rights3Id;
72
73 // 权益3数量
74 private Integer rights3Amount;
75
76 // 状态 0:失效;1:生效
77 private Integer status;
78
79 // 创建时间
80 private Timestamp createTime;
81
82 // 更新时间
83 private Timestamp updateTime;
84 }
1 package com.topdraw.business.basicdata.task.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class TaskQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.task.service.impl;
2
3 import com.topdraw.business.basicdata.task.domain.Task;
4 import com.topdraw.utils.StringUtils;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.basicdata.task.repository.TaskRepository;
7 import com.topdraw.business.basicdata.task.service.TaskService;
8 import com.topdraw.business.basicdata.task.service.dto.TaskDTO;
9 import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria;
10 import com.topdraw.business.basicdata.task.service.mapper.TaskMapper;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Propagation;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.dao.EmptyResultDataAccessException;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Objects;
25
26 /**
27 * @author XiangHan
28 * @date 2021-10-22
29 */
30 @Service
31 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
32 public class TaskServiceImpl implements TaskService {
33
34 @Autowired
35 private TaskRepository TaskRepository;
36
37 @Autowired
38 private TaskMapper TaskMapper;
39
40 @Override
41 public Map<String, Object> queryAll(TaskQueryCriteria criteria, Pageable pageable) {
42 Page<Task> page = TaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
43 return PageUtil.toPage(page.map(TaskMapper::toDto));
44 }
45
46 @Override
47 public List<TaskDTO> queryAll(TaskQueryCriteria criteria) {
48 return TaskMapper.toDto(TaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
49 }
50
51 @Override
52 public TaskDTO findById(Long id) {
53 Task Task = TaskRepository.findById(id).orElseGet(Task::new);
54 ValidationUtil.isNull(Task.getId(),"Task","id",id);
55 return TaskMapper.toDto(Task);
56 }
57
58 @Override
59 @Transactional(rollbackFor = Exception.class)
60 public void create(Task resources) {
61 TaskRepository.save(resources);
62 }
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 public void update(Task resources) {
67 Task Task = TaskRepository.findById(resources.getId()).orElseGet(Task::new);
68 ValidationUtil.isNull( Task.getId(),"Task","id",resources.getId());
69 Task.copy(resources);
70 TaskRepository.save(Task);
71 }
72
73 @Override
74 @Transactional(rollbackFor = Exception.class)
75 public void delete(Long id) {
76 Assert.notNull(id, "The given id must not be null!");
77 Task Task = TaskRepository.findById(id).orElseThrow(
78 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Task.class, id), 1));
79 TaskRepository.delete(Task);
80 }
81
82 @Override
83 public List<Task> findByTemplateId(Long taskTemplateId) {
84 return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null;
85 }
86
87
88 }
1 package com.topdraw.business.basicdata.task.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.task.domain.Task;
5 import com.topdraw.business.basicdata.task.service.dto.TaskDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface TaskMapper extends BaseMapper<TaskDTO, Task> {
15
16 }
1 package com.topdraw.business.basicdata.task.template.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2021-10-22
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="tr_task_template")
24 public class TaskTemplate implements Serializable {
25
26 @Id
27 @GeneratedValue(strategy = GenerationType.IDENTITY)
28 @Column(name = "id")
29 private Long id;
30
31 // 标识
32 @Column(name = "code")
33 private String code;
34
35 // 名称
36 @Column(name = "name")
37 private String name;
38
39 // 关注事件(和MQ topic相关)
40 @Column(name = "event")
41 private String event;
42
43 // 描述
44 @Column(name = "description")
45 private String description;
46
47 // 状态 0:失效;1:生效
48 @Column(name = "status")
49 private Integer status;
50
51 // 类型 0:活动任务模板
52 @Column(name = "type")
53 private Integer type;
54
55 // 模板参数,json
56 @Column(name = "params")
57 private String params;
58
59 @CreatedDate
60 @Column(name = "create_time")
61 private Timestamp createTime;
62
63 @LastModifiedDate
64 @Column(name = "update_time")
65 private Timestamp updateTime;
66
67 public void copy(TaskTemplate source){
68 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
69 }
70 }
1 package com.topdraw.business.basicdata.task.template.repository;
2
3 import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 public interface TaskTemplateRepository extends JpaRepository<TaskTemplate, Long>, JpaSpecificationExecutor<TaskTemplate> {
14
15 Optional<TaskTemplate> findFirstByCode(String code);
16
17 TaskTemplate findByEvent(String event);
18 }
1 package com.topdraw.business.basicdata.task.template.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
6 import com.topdraw.business.basicdata.task.template.service.TaskTemplateService;
7 import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateQueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "TaskTemplate管理")
19 @RestController
20 @RequestMapping("/api/TaskTemplate")
21 public class TaskTemplateController {
22
23 @Autowired
24 private TaskTemplateService TaskTemplateService;
25
26 @GetMapping
27 @ApiOperation("查询TaskTemplate")
28 public ResultInfo getTaskTemplates(TaskTemplateQueryCriteria criteria, Pageable pageable) {
29 return ResultInfo.successPage(TaskTemplateService.queryAll(criteria,pageable));
30 }
31
32 @GetMapping(value = "/all")
33 @ApiOperation("查询所有TaskTemplate")
34 public ResultInfo getTaskTemplates(TaskTemplateQueryCriteria criteria) {
35 return ResultInfo.success(TaskTemplateService.queryAll(criteria));
36 }
37
38 @Log
39 @PostMapping
40 @ApiOperation("新增TaskTemplate")
41 public ResultInfo create(@Validated @RequestBody TaskTemplate resources) {
42 TaskTemplateService.create(resources);
43 return ResultInfo.success();
44 }
45
46 @Log
47 @PutMapping
48 @ApiOperation("修改TaskTemplate")
49 public ResultInfo update(@Validated @RequestBody TaskTemplate resources) {
50 TaskTemplateService.update(resources);
51 return ResultInfo.success();
52 }
53
54
55 @Log
56 @DeleteMapping(value = "/{id}")
57 @ApiOperation("删除TaskTemplate")
58 public ResultInfo delete(@PathVariable Long id) {
59 TaskTemplateService.delete(id);
60 return ResultInfo.success();
61 }
62
63 @GetMapping(value = "/getByCode/{code}")
64 @ApiOperation(value = "根据标识查询")
65 public ResultInfo getByCode(@PathVariable String code) {
66 return ResultInfo.success(TaskTemplateService.getByCode(code));
67 }
68 }
1 package com.topdraw.business.basicdata.task.template.service;
2
3 import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
4 import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateDTO;
5 import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateQueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface TaskTemplateService {
15
16 /**
17 * 查询数据分页
18 * @param criteria 条件参数
19 * @param pageable 分页参数
20 * @return Map<String,Object>
21 */
22 Map<String,Object> queryAll(TaskTemplateQueryCriteria criteria, Pageable pageable);
23
24 /**
25 * 查询所有数据不分页
26 * @param criteria 条件参数
27 * @return List<TaskTemplateDTO>
28 */
29 List<TaskTemplateDTO> queryAll(TaskTemplateQueryCriteria criteria);
30
31 /**
32 * 根据ID查询
33 * @param id ID
34 * @return TaskTemplateDTO
35 */
36 TaskTemplateDTO findById(Long id);
37
38 void create(TaskTemplate resources);
39
40 void update(TaskTemplate resources);
41
42 void delete(Long id);
43
44 /**
45 * Code校验
46 * @param code
47 * @return TaskTemplateDTO
48 */
49 TaskTemplateDTO getByCode(String code);
50
51 TaskTemplate findByEvent(String event);
52 }
1 package com.topdraw.business.basicdata.task.template.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class TaskTemplateDTO implements Serializable {
14
15 private Long id;
16
17 // 标识
18 private String code;
19
20 // 名称
21 private String name;
22
23 // 关注事件(和MQ topic相关)
24 private String event;
25
26 // 描述
27 private String description;
28
29 // 状态 0:失效;1:生效
30 private Integer status;
31
32 // 类型 0:活动任务模板
33 private Integer type;
34
35 // 模板参数,json
36 private String params;
37
38 private Timestamp createTime;
39
40 private Timestamp updateTime;
41 }
1 package com.topdraw.business.basicdata.task.template.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2021-10-22
8 */
9 @Data
10 public class TaskTemplateQueryCriteria{
11 }
1 package com.topdraw.business.basicdata.task.template.service.impl;
2
3 import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
4 import com.topdraw.utils.ValidationUtil;
5 import com.topdraw.business.basicdata.task.template.repository.TaskTemplateRepository;
6 import com.topdraw.business.basicdata.task.template.service.TaskTemplateService;
7 import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateDTO;
8 import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateQueryCriteria;
9 import com.topdraw.business.basicdata.task.template.service.mapper.TaskTemplateMapper;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.stereotype.Service;
12 import org.springframework.transaction.annotation.Propagation;
13 import org.springframework.transaction.annotation.Transactional;
14 import org.springframework.dao.EmptyResultDataAccessException;
15 import org.springframework.data.domain.Page;
16 import org.springframework.data.domain.Pageable;
17 import org.springframework.util.Assert;
18 import com.topdraw.utils.PageUtil;
19 import com.topdraw.utils.QueryHelp;
20 import com.topdraw.utils.StringUtils;
21
22 import java.util.List;
23 import java.util.Map;
24
25 /**
26 * @author XiangHan
27 * @date 2021-10-22
28 */
29 @Service
30 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
31 public class TaskTemplateServiceImpl implements TaskTemplateService {
32
33 @Autowired
34 private TaskTemplateRepository TaskTemplateRepository;
35
36 @Autowired
37 private TaskTemplateMapper TaskTemplateMapper;
38
39 @Override
40 public Map<String, Object> queryAll(TaskTemplateQueryCriteria criteria, Pageable pageable) {
41 Page<TaskTemplate> page = TaskTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
42 return PageUtil.toPage(page.map(TaskTemplateMapper::toDto));
43 }
44
45 @Override
46 public List<TaskTemplateDTO> queryAll(TaskTemplateQueryCriteria criteria) {
47 return TaskTemplateMapper.toDto(TaskTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
48 }
49
50 @Override
51 public TaskTemplateDTO findById(Long id) {
52 TaskTemplate TaskTemplate = TaskTemplateRepository.findById(id).orElseGet(TaskTemplate::new);
53 ValidationUtil.isNull(TaskTemplate.getId(),"TaskTemplate","id",id);
54 return TaskTemplateMapper.toDto(TaskTemplate);
55 }
56
57 @Override
58 @Transactional(rollbackFor = Exception.class)
59 public void create(TaskTemplate resources) {
60 TaskTemplateRepository.save(resources);
61 }
62
63 @Override
64 @Transactional(rollbackFor = Exception.class)
65 public void update(TaskTemplate resources) {
66 TaskTemplate TaskTemplate = TaskTemplateRepository.findById(resources.getId()).orElseGet(TaskTemplate::new);
67 ValidationUtil.isNull( TaskTemplate.getId(),"TaskTemplate","id",resources.getId());
68 TaskTemplate.copy(resources);
69 TaskTemplateRepository.save(TaskTemplate);
70 }
71
72 @Override
73 @Transactional(rollbackFor = Exception.class)
74 public void delete(Long id) {
75 Assert.notNull(id, "The given id must not be null!");
76 TaskTemplate TaskTemplate = TaskTemplateRepository.findById(id).orElseThrow(
77 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", TaskTemplate.class, id), 1));
78 TaskTemplateRepository.delete(TaskTemplate);
79 }
80
81
82 @Override
83 public TaskTemplateDTO getByCode(String code) {
84 return StringUtils.isNotEmpty(code) ? TaskTemplateMapper.toDto(TaskTemplateRepository.findFirstByCode(code).orElseGet(TaskTemplate::new))
85 : new TaskTemplateDTO();
86 }
87
88 @Override
89 public TaskTemplate findByEvent(String event) {
90 return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null;
91 }
92 }
1 package com.topdraw.business.basicdata.task.template.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
5 import com.topdraw.business.basicdata.task.template.service.dto.TaskTemplateDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface TaskTemplateMapper extends BaseMapper<TaskTemplateDTO, TaskTemplate> {
15
16 }
1 package com.topdraw.business.process.domian;
2
3 public enum RightType {
4 /**积分*/
5 POINTS,
6 /**成长值*/
7 EXP,
8 /**优惠券券*/
9 COUPON,
10 /**权益统称*/
11 RIGHTS
12
13 }
1 package com.topdraw.business.process.domian;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
6
7 import javax.persistence.Transient;
8 import java.sql.Timestamp;
9
10 /**
11 * 权益-非持久化数据
12 */
13 @Data
14 @AllArgsConstructor
15 @NoArgsConstructor
16 public class TempCoupon extends TempRights {
17
18 @Transient
19 protected String code;
20
21 @Transient
22 protected Integer useStatus;
23
24 @Transient
25 protected Timestamp useTime;
26
27 /**领取时间*/
28 @Transient
29 protected Timestamp receiveTime;
30
31 @Transient
32 protected String userNickname;
33
34 }
1 package com.topdraw.business.process.domian;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
6
7 import javax.persistence.Transient;
8
9 /**
10 * 权益-非持久化数据
11 */
12 @Data
13 @AllArgsConstructor
14 @NoArgsConstructor
15 public class TempExp extends TempRights {
16
17 // 获得成长值
18 @Transient
19 protected Long rewardExp;
20
21
22 }
1 package com.topdraw.business.process.domian;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
6 import lombok.ToString;
7
8 import javax.persistence.Transient;
9 import javax.validation.constraints.NotNull;
10
11 /**
12 * 权益-非持久化数据
13 */
14 @Data
15 @AllArgsConstructor
16 @NoArgsConstructor
17 @ToString
18 public class TempPoints extends TempRights {
19
20 // 获得积分
21 @Transient
22 @NotNull(message = "【points】积分数值不得为空!!")
23 protected Long points;
24
25 // 积分类型 0:通用
26 @Transient
27 @NotNull(message = "【pointsType】积分类型不得为空!!")
28 protected Integer pointsType;
29
30 @Transient
31 protected Long rewardPointsExpireTime;
32
33 }
1 package com.topdraw.business.process.domian;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
6
7 import javax.persistence.Transient;
8 import javax.validation.constraints.NotNull;
9 import java.sql.Timestamp;
10
11 /**
12 * 权益-非持久化数据
13 */
14 @Data
15 @AllArgsConstructor
16 @NoArgsConstructor
17 public class TempRights {
18
19 /** 主键 */
20 @Transient
21 protected Long id;
22
23 /** 会员ID */
24 @Transient
25 @NotNull(message = "")
26 protected Long memberId;
27
28 /** 账号id */
29 @Transient
30 protected Long userId;
31
32 /** 发放策略 */
33 @Transient
34 protected Integer rightsSendStrategy;
35
36 /** 账号id */
37 @Transient
38 private Long accountId;
39
40 /** 过期时间 */
41 @Transient
42 protected Timestamp expireTime;
43
44
45 /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */
46 @Transient
47 @NotNull(message = "")
48 protected Integer deviceType;
49
50 /** 应用code(表示当前用户对应应用的标识) */
51 @Transient
52 // @NotNull
53 protected String appCode;
54
55 /** 订单id */
56 @Transient
57 protected Long orderId;
58
59 /** 节目id(针对观影操作) */
60 @Transient
61 protected Long mediaId;
62
63 /** 活动id(针对参与活动) */
64 @Transient
65 protected Long activityId;
66
67 /** 商品id */
68 @Transient
69 protected Long itemId;
70
71 /** 积分变化描述,用于管理侧显示 */
72 @Transient
73 protected String description;
74
75 /** 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他 */
76 @Transient
77 protected Integer evtType;
78
79 /** 数量 */
80 @Transient
81 protected Integer rightsAmount;
82
83 }
1 package com.topdraw.business.process.rest;
2
3 import com.topdraw.annotation.Log;
4 import com.topdraw.business.process.domian.TempCoupon;
5 import com.topdraw.business.process.service.CouponOperationService;
6 import com.topdraw.common.ResultInfo;
7 import io.swagger.annotations.Api;
8 import io.swagger.annotations.ApiOperation;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.web.bind.annotation.*;
11
12 import java.util.List;
13
14 /**
15 * @author XiangHan
16 * @date 2021-10-22
17 */
18 @Api(tags = "CouponOperation管理")
19 @RestController
20 @RequestMapping("/api/CouponOperation")
21 public class CouponOperationController {
22
23 @Autowired
24 private CouponOperationService couponOperationService;
25
26 @Log
27 @PostMapping(value = "/grantCouponByManual")
28 @ApiOperation("手动发放优惠券")
29 public ResultInfo grantCouponByManual(Long memberId , Long userId , List<TempCoupon> tempCouponList) {
30 this.couponOperationService.grantCouponByManual(memberId,userId,tempCouponList);
31 return ResultInfo.success();
32 }
33
34 }
1 package com.topdraw.business.process.rest;
2
3 import com.topdraw.annotation.Log;
4 import com.topdraw.business.process.domian.TempCoupon;
5 import com.topdraw.business.process.domian.TempExp;
6 import com.topdraw.business.process.service.CouponOperationService;
7 import com.topdraw.business.process.service.ExpOperationService;
8 import com.topdraw.common.ResultInfo;
9 import io.swagger.annotations.Api;
10 import io.swagger.annotations.ApiOperation;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.PostMapping;
14 import org.springframework.web.bind.annotation.RequestBody;
15 import org.springframework.web.bind.annotation.RequestMapping;
16 import org.springframework.web.bind.annotation.RestController;
17
18 import java.util.Arrays;
19 import java.util.List;
20
21 /**
22 * @author XiangHan
23 * @date 2021-10-22
24 */
25 @Api(tags = "ExpOperation管理")
26 @RestController
27 @RequestMapping("/api/ExpOperation")
28 public class ExpOperationController {
29
30 @Autowired
31 private ExpOperationService expOperationService;
32
33 @Log
34 @PostMapping(value = "/grantExpByManual")
35 @ApiOperation("手动发放成长值")
36 public ResultInfo grantExpByManual(@Validated @RequestBody TempExp tempExp) {
37 List<TempExp> tempExpList = Arrays.asList(tempExp);
38 this.expOperationService.grantExpByManual(tempExpList);
39 return ResultInfo.success();
40 }
41
42 }
1 package com.topdraw.business.process.rest;
2
3 import com.topdraw.annotation.Log;
4 import com.topdraw.business.basicdata.points.available.service.PointsAvailableService;
5 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria;
6 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryType;
7 import com.topdraw.business.basicdata.points.detail.service.PointsDetailService;
8 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailQueryCriteria;
9 import com.topdraw.business.process.domian.TempPoints;
10 import com.topdraw.business.process.service.PointsOperationService;
11 import com.topdraw.common.ResultInfo;
12 import com.topdraw.util.TimestampUtil;
13 import io.swagger.annotations.Api;
14 import io.swagger.annotations.ApiOperation;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.data.domain.Pageable;
19 import org.springframework.util.Assert;
20 import org.springframework.validation.annotation.Validated;
21 import org.springframework.web.bind.annotation.*;
22
23 /**
24 * @author XiangHan
25 * @date 2021-10-22
26 */
27 @Api(tags = "PointsOperation管理")
28 @RestController
29 @RequestMapping("/api/PointsOperation")
30 public class PointsOperationController {
31
32 private static final Logger LOG = LoggerFactory.getLogger(PointsOperationController.class);
33
34 @Autowired
35 private PointsOperationService pointsOperationService;
36 @Autowired
37 private PointsDetailService pointsDetailService;
38 @Autowired
39 private PointsAvailableService pointsAvailableService;
40
41 @GetMapping(value = "/pagePointsDetails")
42 @ApiOperation("查询PointsDetail")
43 public ResultInfo pagePointsDetails(PointsDetailQueryCriteria criteria, Pageable pageable) {
44 return ResultInfo.successPage(pointsDetailService.queryAll(criteria,pageable));
45 }
46
47 @GetMapping(value = "/pageAvailablePoints")
48 @ApiOperation("查询PointsAvailable")
49 public ResultInfo pageAvailablePoints(PointsAvailableQueryCriteria criteria, Pageable pageable) {
50 PointsAvailableQueryType queryType = criteria.getQueryType();
51 // 可用
52 if (queryType == PointsAvailableQueryType.AVAILABLE_ONLY) {
53 criteria.setExpireTime(TimestampUtil.now());
54 }
55 return ResultInfo.successPage(pointsAvailableService.queryAll(criteria,pageable));
56 }
57
58 @Log
59 @PostMapping(value = "/grantPointsByManual")
60 @ApiOperation("新增PointsDetail")
61 public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) {
62 Long memberId = tempPoints.getMemberId();
63 LOG.info("PointsOperationController -->> grantPointsByManual -->> " + tempPoints);
64 this.pointsOperationService.grantPointsByManual(memberId,tempPoints);
65 return ResultInfo.success();
66 }
67
68 @Log
69 @PostMapping(value = "/customPoints")
70 @ApiOperation("积分消耗")
71 public ResultInfo customPoints(@Validated @RequestBody TempPoints tempPoints) {
72 this.pointsOperationService.customPoints(tempPoints);
73 return ResultInfo.success();
74 }
75 }
1 package com.topdraw.business.process.rest;
2
3 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
4 import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService;
5 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria;
6 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryType;
7 import com.topdraw.business.process.service.RightsOperationService;
8 import com.topdraw.common.ResultInfo;
9 import com.topdraw.annotation.Log;
10 import com.topdraw.business.basicdata.rights.domain.Rights;
11 import com.topdraw.business.basicdata.rights.service.RightsService;
12 import com.topdraw.util.TimestampUtil;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.data.domain.Pageable;
15 import org.springframework.validation.annotation.Validated;
16 import org.springframework.web.bind.annotation.*;
17 import io.swagger.annotations.*;
18
19 import java.util.Arrays;
20 import java.util.List;
21
22
23 /**
24 * @author XiangHan
25 * @date 2021-10-22
26 */
27 @Api(tags = "Rights管理")
28 @RestController
29 @RequestMapping("/api/RightsOperation")
30 public class RightsOperationController {
31
32 @Autowired
33 private RightsOperationService rightsOperationService;
34 @Autowired
35 private RightsHistoryService rightsHistoryService;
36 @Autowired
37 private RightsService rightsService;
38
39 @GetMapping
40 @ApiOperation("查询RightsHistory")
41 public ResultInfo queryRightsHistory(RightsHistoryQueryCriteria criteria, Pageable pageable) {
42 RightsHistoryQueryType queryType = criteria.getQueryType();
43 if (queryType == RightsHistoryQueryType.AVAILABLE_ONLY) {
44 criteria.setExpireTime(TimestampUtil.now());
45 }
46 return ResultInfo.successPage(rightsHistoryService.queryAll(criteria,pageable));
47 }
48
49 @GetMapping(value = "/findRightsHistoryById/{id}")
50 @ApiOperation("查询RightsHistory")
51 public ResultInfo findRightsHistoryById(@PathVariable Long id) {
52 return ResultInfo.success(rightsHistoryService.findById(id));
53 }
54
55
56 @PostMapping(value = "/grantRightsByManual")
57 @ApiOperation("查询RightsHistory")
58 public ResultInfo grantRightsByManual(@Validated @RequestBody RightsHistory rightsHistory) {
59 List<RightsHistory> rightsHistories = Arrays.asList(rightsHistory);
60 this.rightsOperationService.grantRightsByManual(rightsHistories);
61 return ResultInfo.success();
62 }
63
64
65 }
1 package com.topdraw.business.process.rest;
2
3 import com.topdraw.annotation.Log;
4 import com.topdraw.business.process.service.TaskOperationService;
5 import io.swagger.annotations.Api;
6 import io.swagger.annotations.ApiOperation;
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.validation.annotation.Validated;
9 import org.springframework.web.bind.annotation.*;
10
11 @Api("任务处理")
12 @RestController
13 @RequestMapping(value = "/api/TaskOperation")
14 public class TaskOperationController {
15
16 @Autowired
17 TaskOperationService taskOperationService;
18
19 /**
20 * 处理事件
21 *
22 * @param criteria 消息
23 */
24 @Log
25 @PostMapping(value = "/dealTask")
26 @ApiOperation("事件处理")
27 public void dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) {
28 // 任务处理
29 this.taskOperationService.dealTask(criteria.getContent());
30 }
31
32
33 }
34
35
1 package com.topdraw.business.process.rest;
2
3 import lombok.Data;
4
5 import javax.validation.constraints.NotNull;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-10-22
11 */
12 @Data
13 public class TaskOperationQueryCriteria {
14
15 @NotNull(message = "【content】 not be null !!!")
16 private String content;
17
18 }
1 package com.topdraw.business.process.service;
2
3 import com.topdraw.business.basicdata.coupon.domain.Coupon;
4 import com.topdraw.business.process.domian.TempCoupon;
5 import com.topdraw.business.process.domian.TempRights;
6
7 import java.util.List;
8
9 /**
10 * @description 权益操作接口
11 * @author XiangHan
12 * @date 2021.10.22
13 */
14
15 public interface CouponOperationService {
16
17 /**
18 * 基于已完成的任务发放优惠券
19 * @param tempCouponList
20 */
21 void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList);
22
23 /**
24 * 系统手动发放优惠券
25 * @param memberId
26 * @param userId
27 * @param tempCouponList
28 */
29 void grantCouponByManual(Long memberId,Long userId ,List<TempCoupon> tempCouponList);
30 }
1 package com.topdraw.business.process.service;
2
3 import com.topdraw.business.process.domian.TempCoupon;
4 import com.topdraw.business.process.domian.TempExp;
5 import com.topdraw.business.process.domian.TempRights;
6
7 import java.util.List;
8
9 /**
10 * @description 权益操作接口
11 * @author XiangHan
12 * @date 2021.10.22
13 */
14 public interface ExpOperationService {
15
16 /**
17 * 任务完成后自动发放成长值
18 * @param tempExpList
19 */
20 void grantPointsThroughTempExp( List<TempExp> tempExpList);
21
22 /**
23 * 系统手动发放优惠券
24 * @param memberId
25 * @param userId
26 * @param tempExpList
27 */
28 void grantExpByManual(Long memberId,Long userId ,List<TempExp> tempExpList);
29
30 void grantExpByManual(List<TempExp> tempExpList);
31
32 }
1 package com.topdraw.business.process.service;
2
3 import com.topdraw.business.basicdata.member.domain.Member;
4 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
5
6 public interface MemberOperationService {
7
8 void doUpdateMemberInfo(Member member);
9
10 void doInsertMember(Member member);
11
12 MemberDTO findById(Long memberId);
13
14 void doUpdateMemberExp(Member member);
15
16 void doUpdateMemberPoints(Member member);
17
18 void doUpdateMemberCoupon(Member member);
19 }
1 package com.topdraw.business.process.service;
2
3 import com.topdraw.business.basicdata.points.domain.Points;
4 import com.topdraw.business.basicdata.task.domain.Task;
5 import com.topdraw.business.process.domian.TempPoints;
6
7 import java.util.List;
8
9 /**
10 * @description 积分操作接口
11 * @author XiangHan
12 * @date 2021.10.22
13 */
14 public interface PointsOperationService {
15
16 /**
17 * 手动发放积分
18 * @param memberId 会员id
19 * @param tempPoints 积分详情
20 */
21 void grantPointsByManual(Long memberId , TempPoints tempPoints);
22
23
24 /**
25 * 积分扣减
26 * @param tempPoints 积分对象
27 */
28 boolean customPoints(TempPoints tempPoints);
29
30
31 /**
32 * 积分发放,基于已获得的权益
33 * @param tempPointsList 已获得的权益
34 */
35 void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList);
36
37 /**
38 * 清理过期的积分
39 */
40 void cleanInvalidAvailablePoints();
41 }
1 package com.topdraw.business.process.service;
2
3 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
4 import com.topdraw.business.process.domian.RightType;
5
6 import java.util.List;
7 import java.util.Map;
8
9 /**
10 * @description 权益操作接口
11 * @author XiangHan
12 * @date 2021.10.22
13 */
14 public interface RightsOperationService {
15
16 /**
17 * 系统手动发放权益
18 * @param rightsHistories
19 */
20 void grantRightsByManual(List<RightsHistory> rightsHistories);
21
22 /**
23 * 任务完成自动发放权益
24 * @param tempRightsMap
25 */
26 void grantRights(Map<RightType, Object> tempRightsMap);
27 }
1 package com.topdraw.business.process.service;
2
3 public interface TaskDealService {
4
5 }
1 package com.topdraw.business.process.service;
2
3 import com.topdraw.module.mq.DataSyncMsg;
4
5 /**
6 * @description 权益操作接口
7 * @author XiangHan
8 * @date 2021.10.22
9 */
10 public interface TaskOperationService {
11
12 /**
13 * 处理任务
14 *
15 * @param content 任务对象
16 */
17 void dealTask(String content);
18
19
20 }
1 package com.topdraw.business.process.service.impl;
2
3 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
4 import com.topdraw.business.basicdata.task.domain.Task;
5 import com.topdraw.util.TimestampUtil;
6 import org.springframework.util.CollectionUtils;
7
8 import java.util.List;
9 import java.util.stream.Collectors;
10
11 @FunctionalInterface
12 public interface CompareTaskCondition {
13
14 boolean compareCondition(MemberDTO memberDTO, List<Task> taskList);
15
16 }
1 package com.topdraw.business.process.service.impl;
2
3 import com.topdraw.business.basicdata.coupon.history.domain.CouponHistory;
4 import com.topdraw.business.basicdata.coupon.history.service.CouponHistoryService;
5 import com.topdraw.business.basicdata.coupon.service.CouponService;
6 import com.topdraw.business.basicdata.member.domain.Member;
7 import com.topdraw.business.process.service.CouponOperationService;
8 import com.topdraw.business.process.service.MemberOperationService;
9 import com.topdraw.business.process.domian.TempCoupon;
10 import com.topdraw.business.process.service.RightsOperationService;
11 import com.topdraw.util.TimestampUtil;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.BeanUtils;
15 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.stereotype.Service;
17
18 import java.sql.Timestamp;
19 import java.time.LocalDateTime;
20 import java.util.List;
21 import java.util.Objects;
22 import java.util.concurrent.locks.ReentrantLock;
23
24
25 @Service
26 public class CouponOperationServiceImpl implements CouponOperationService {
27
28 private static final Logger LOG = LoggerFactory.getLogger(CouponOperationServiceImpl.class);
29
30 @Autowired
31 CouponService couponService;
32 @Autowired
33 CouponHistoryService couponHistoryService;
34 @Autowired
35 MemberOperationService memberOperationService;
36 @Autowired
37 RightsOperationService rightsOperationService;
38
39 // 过期阀值(默认一个月)
40 private static final Integer EXPIRE_FACTOR_MONTH = 1;
41
42 private ReentrantLock reentrantLock = new ReentrantLock(true);
43
44 @Override
45 public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) {
46 // 优惠券领取、使用历史记录表
47 for (TempCoupon tempCoupon : tempCouponList) {
48 this.refresh(tempCoupon);
49 }
50 }
51
52 /**
53 * 手动发放优惠券
54 * @param memberId 会员id
55 * @param tempCouponList
56 */
57 @Override
58 public void grantCouponByManual(Long memberId,Long userId ,List<TempCoupon> tempCouponList) {
59 // 优惠券领取、使用历史记录表
60 for (TempCoupon tempCoupon : tempCouponList) {
61 this.refresh(tempCoupon);
62 }
63 }
64
65
66 /**
67 * 优惠券领取历史记录表
68 *
69 * @param tempCoupon 领取的优惠券
70 */
71 private void refresh(TempCoupon tempCoupon) {
72 // 1.保存优惠券领取、使用历史记录表
73 this.doInsertCouponHistory(tempCoupon);
74 // 2.更新会员优惠券数量
75 this.refreshMemberCoupon(tempCoupon);
76 }
77
78
79 /**
80 * 更新会员优惠券信息
81 * @param tempCoupon 账号id
82 */
83 private void refreshMemberCoupon(TempCoupon tempCoupon) {
84 Long userId = tempCoupon.getUserId();
85 Long memberId = tempCoupon.getMemberId();
86 try{
87 // reentrantLock.lock();
88 // 1.获取用户领取的总优惠券
89 Long totalCouponCount = this.getTotalCoupon(userId);
90 // 2.获取已过期的优惠券数量
91 Long expireCouponCount = this.getTotalExpireCoupon(userId);
92 // 3.即将过期的优惠券数量
93 Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(userId,EXPIRE_FACTOR_MONTH);
94 // 4.当前优惠券数量 = 总优惠券-已过期的优惠券
95 Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount);
96 // 5.更新用户信息(优惠券数量、即将过期的优惠券数量)
97 this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount);
98 } catch (Exception e) {
99 e.printStackTrace();
100 throw e;
101 } finally {
102 // reentrantLock.unlock();
103 }
104
105 }
106
107
108 /**
109 * 更新当前用户优惠券信息
110 * @param memberId
111 * @param currentCoupon
112 * @param expireSoonCouponCount
113 */
114 private void doUpdateMemberInfo(Long memberId, Long currentCoupon, Long expireSoonCouponCount) {
115 Member member = new Member();
116 member.setId(memberId);
117 member.setCouponAmount(currentCoupon);
118 member.setDueCouponAmount(expireSoonCouponCount);
119 member.setUpdateTime(TimestampUtil.now());
120 this.memberOperationService.doUpdateMemberInfo(member);
121 }
122
123
124 /**
125 * 当前优惠券数量 = 总优惠券-已过期的优惠券
126 * @param totalCouponCount 总数
127 * @param expireCouponCount 已过期总数
128 * @return
129 */
130 private Long getCurrentCoupon(Long totalCouponCount, Long expireCouponCount) {
131 return (Objects.nonNull(totalCouponCount)?totalCouponCount:0L)-(Objects.nonNull(expireCouponCount)?expireCouponCount:0L);
132 }
133
134
135 /**
136 * 即将过期的优惠券数量
137 * @param expireFactor
138 * @return
139 */
140 private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) {
141 LocalDateTime localDateTime = LocalDateTime.now();
142 String s = EXPIRE_FACTOR_MONTH.toString();
143 String[] s1 = s.split("_");
144 String s2 = s1[s1.length-1];
145 switch (s2) {
146 case "YEAR":
147 localDateTime.plusYears(expireFactor);
148 break;
149 case "MONTH":
150 localDateTime.plusMonths(expireFactor);
151 break;
152 case "DAY":
153 localDateTime.plusDays(expireFactor);
154 break;
155 case "HOUR":
156 localDateTime.plusHours(expireFactor);
157 break;
158 default:
159 break;
160 }
161
162 Timestamp expireTime = TimestampUtil.now(localDateTime);
163 return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime);
164 }
165
166
167 /**
168 * 获取已过期的优惠券数量
169 * @param userId
170 * @return
171 */
172 private Long getTotalExpireCoupon(Long userId) {
173 return this.couponHistoryService.countByUserIdAndExpireTimeBefore(userId,TimestampUtil.now());
174 }
175
176
177 /**
178 * 获取用户领取的总优惠券
179 * @param userId
180 * @return
181 */
182 private Long getTotalCoupon(Long userId) {
183 return this.couponHistoryService.countByUserId(userId);
184 }
185
186
187 /**
188 * 优惠券领取、使用历史记录表
189 * @param tempCoupon 优惠券
190 */
191 private void doInsertCouponHistory(TempCoupon tempCoupon) {
192 CouponHistory couponHistory = new CouponHistory();
193 BeanUtils.copyProperties(tempCoupon,couponHistory);
194 couponHistory.setId(null);
195 couponHistory.setCouponId(tempCoupon.getId());
196 couponHistory.setUserId(tempCoupon.getUserId());
197 couponHistory.setCouponCode(tempCoupon.getCode());
198 couponHistory.setUserNickname(tempCoupon.getUserNickname());
199 couponHistory.setOrderDetailId(tempCoupon.getOrderId());
200 this.couponHistoryService.create(couponHistory);
201 }
202
203
204 }
1 package com.topdraw.business.process.service.impl;
2
3 import com.topdraw.business.basicdata.exp.detail.domain.ExpDetail;
4 import com.topdraw.business.basicdata.exp.detail.service.ExpDetailService;
5 import com.topdraw.business.basicdata.member.domain.Member;
6 import com.topdraw.business.basicdata.member.level.service.MemberLevelService;
7 import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO;
8 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
9 import com.topdraw.business.process.service.ExpOperationService;
10 import com.topdraw.business.process.service.MemberOperationService;
11 import com.topdraw.business.process.domian.TempExp;
12 import com.topdraw.util.IdWorker;
13 import com.topdraw.util.TimestampUtil;
14 import com.topdraw.utils.StringUtils;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.springframework.beans.BeanUtils;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service;
20 import org.springframework.util.CollectionUtils;
21
22 import java.util.List;
23 import java.util.Objects;
24 import java.util.concurrent.locks.Lock;
25 import java.util.concurrent.locks.ReentrantLock;
26 import java.util.concurrent.locks.ReentrantReadWriteLock;
27
28 /**
29 *
30 */
31 @Service
32 public class ExpOperationServiceImpl implements ExpOperationService {
33
34 private static final Logger LOG = LoggerFactory.getLogger(ExpOperationServiceImpl.class);
35
36 @Autowired
37 ExpDetailService expDetailService;
38 @Autowired
39 MemberOperationService memberOperationService;
40 @Autowired
41 MemberLevelService memberLevelService;
42
43 @Override
44 public void grantPointsThroughTempExp(List<TempExp> tempExpList) {
45
46 for (TempExp tempExp : tempExpList) {
47 this.refresh(tempExp);
48 }
49
50 }
51
52 @Override
53 public void grantExpByManual(Long memberId, Long userId, List<TempExp> tempExpList) {
54 for (TempExp tempExp : tempExpList) {
55 this.refresh(tempExp);
56 }
57 }
58
59 @Override
60 public void grantExpByManual(List<TempExp> tempExpList) {
61 for (TempExp tempExp : tempExpList) {
62 this.refresh(tempExp);
63 }
64 }
65
66
67 /**
68 *
69 * @param tempExp
70 */
71 private void refresh(TempExp tempExp) {
72 // 1.添加成长值记录
73 this.doInsertExpDetail(tempExp);
74
75 // 2.更新成长值与等级
76 this.refreshMemberExpAndLevel(tempExp);
77 }
78
79
80 /**
81 * 更新成长值与等级
82 *
83 * @param tempExp 成长值列表
84 */
85 private void refreshMemberExpAndLevel(TempExp tempExp) {
86 Long memberId = tempExp.getMemberId();
87 // 1.获取当前成长值
88 MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId);
89 // 2.获取下一级需要的成长值
90 MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel()+1,1);
91 // 3.成长值累加
92 Long newExp = memberDTO.getExp() + tempExp.getRewardExp();
93 // 4.成长值比较,判断是否升级
94 long i = this.compareExp(newExp,memberLevelDTO);
95 // 5.更新用户信息
96 this.updateMemberInfo(i,newExp,memberLevelDTO,memberId);
97 }
98
99 /**
100 *
101 * @param i
102 * @param newExp 总积分
103 * @param memberLevelDTO 下一级
104 * @param memberId 会员id
105 */
106 private void updateMemberInfo(long i,Long newExp,MemberLevelDTO memberLevelDTO,Long memberId) {
107 Member member = new Member();
108 member.setId(memberId);
109 member.setExp(newExp);
110 if (i > 0) {
111 Integer level = memberLevelDTO.getLevel();
112 member.setLevel(level);
113 }
114 member.setUpdateTime(TimestampUtil.now());
115 this.memberOperationService.doUpdateMemberInfo(member);
116 }
117
118 private long compareExp(long newExp, MemberLevelDTO memberLevelDTO) {
119 if (Objects.nonNull(memberLevelDTO)) {
120 Long nextLevelExp = memberLevelDTO.getExpValue();
121 if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0)
122 return newExp - nextLevelExp;
123 }
124 return -1;
125 }
126
127 private MemberLevelDTO getNextLevelExp(Integer i,Integer status) {
128 List<MemberLevelDTO> memberLevelDTOList = this.memberLevelService.findLevelAndStatus(i,status);
129 if (!CollectionUtils.isEmpty(memberLevelDTOList)) {
130 return memberLevelDTOList.get(0);
131 }
132 return null;
133 }
134
135
136 /**
137 * 获取当前会员的成长值
138 * @param memberId 会员id
139 * @return Long 当前会员成长值
140 */
141 private MemberDTO getMemberInfoByMemberId(Long memberId) {
142 MemberDTO memberDTO = this.memberOperationService.findById(memberId);
143 return memberDTO;
144 }
145
146
147 /**
148 * 添加成长值记录
149 *
150 * @param tempExp 成长值列表
151 */
152 private void doInsertExpDetail(TempExp tempExp) {
153
154 ExpDetail expDetail = new ExpDetail();
155 BeanUtils.copyProperties(tempExp,expDetail);
156
157 MemberDTO memberDTO = this.memberOperationService.findById(expDetail.getMemberId());
158 Long exp = memberDTO.getExp();
159
160 Long rewardExp = tempExp.getRewardExp();
161 Long originalExp = exp;
162
163 expDetail.setCode(String.valueOf(IdWorker.generator()));
164 expDetail.setOriginalExp(Objects.nonNull(originalExp) ? originalExp : 0L);
165 expDetail.setResultExp((Objects.nonNull(rewardExp) ? rewardExp : 0L) + (Objects.nonNull(originalExp) ? originalExp : 0L));
166 expDetail.setExp(rewardExp);
167 if (StringUtils.isEmpty(expDetail.getDescription())) {
168 expDetail.setDescription("#");
169 }
170 this.expDetailService.create(expDetail);
171 }
172
173 }
1 package com.topdraw.business.process.service.impl;
2
3 import com.topdraw.business.basicdata.member.domain.Member;
4 import com.topdraw.business.basicdata.member.service.MemberService;
5 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
6 import com.topdraw.business.process.service.MemberOperationService;
7 import org.redisson.Redisson;
8 import org.redisson.api.RedissonClient;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.util.Assert;
12
13 import java.util.Objects;
14
15 @Service
16 public class MemberOperationServiceImpl implements MemberOperationService {
17
18 @Autowired
19 MemberService memberService;
20
21 @Override
22 public void doUpdateMemberInfo(Member member) {
23 Long id = member.getId();
24 Assert.notNull(id,"ERROR MSG: MemberOperationServiceImpl -> doUpdateMemberInfo -> id not be null!!");
25 this.memberService.update(member);
26 }
27
28 @Override
29 public void doInsertMember(Member member) {
30 this.memberService.create(member);
31 }
32
33 @Override
34 public MemberDTO findById(Long memberId) {
35 return Objects.nonNull(memberId) ? this.memberService.findById(memberId) : null;
36 }
37
38 @Override
39 public void doUpdateMemberExp(Member member) {
40 this.doUpdateMemberInfo(member);
41 }
42
43 @Override
44 public void doUpdateMemberPoints(Member member) {
45 this.doUpdateMemberInfo(member);
46 }
47
48 @Override
49 public void doUpdateMemberCoupon(Member member) {
50 this.doUpdateMemberInfo(member);
51 }
52 }
1 package com.topdraw.business.process.service.impl;
2
3 import cn.hutool.core.map.MapUtil;
4 import com.topdraw.business.basicdata.member.domain.Member;
5 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
6 import com.topdraw.business.basicdata.points.available.domain.PointsAvailable;
7 import com.topdraw.business.basicdata.points.available.service.PointsAvailableService;
8 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
9 import com.topdraw.business.basicdata.points.detail.detailhistory.service.PointsDetailHistoryService;
10 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
11 import com.topdraw.business.basicdata.points.detail.service.PointsDetailService;
12 import com.topdraw.business.basicdata.points.service.PointsService;
13 import com.topdraw.business.process.service.MemberOperationService;
14 import com.topdraw.business.process.service.PointsOperationService;
15 import com.topdraw.business.process.domian.TempPoints;
16 import com.topdraw.util.IdWorker;
17 import com.topdraw.util.TimestampUtil;
18 import com.topdraw.utils.StringUtils;
19 import org.redisson.api.RedissonClient;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.beans.BeanUtils;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Service;
25 import org.springframework.transaction.annotation.Propagation;
26 import org.springframework.transaction.annotation.Transactional;
27 import org.springframework.util.CollectionUtils;
28
29 import java.sql.Time;
30 import java.sql.Timestamp;
31 import java.time.LocalDateTime;
32 import java.util.*;
33 import java.util.stream.Collectors;
34
35 /**
36 *
37 */
38 @Service
39 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
40 public class PointsOperationServiceImpl implements PointsOperationService {
41
42 private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class);
43
44 @Autowired
45 PointsService pointsService;
46 @Autowired
47 PointsDetailService pointsDetailService;
48 @Autowired
49 PointsAvailableService pointsAvailableService;
50 @Autowired
51 PointsDetailHistoryService pointsDetailHistoryService;
52 @Autowired
53 MemberOperationService memberOperationService;
54
55 // 过期阈值 30天
56 private static final Integer EXPIRE_FACTOR = 30;
57
58 private static final String DELETE_AVAILABLE_POINTS = "delete";
59 private static final String INSERT_AVAILABLE_POINTS = "insert";
60
61 @Autowired
62 private RedissonClient redissonClient;
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 public void grantPointsByManual(Long memberId,TempPoints tempPoints){
67 this.refresh(tempPoints);
68 }
69
70 /**
71 * 积分消耗
72 * @param tempPoints 任务对象
73 * @return true: 满足 false:不满足
74 */
75 @Override
76 @Transactional(rollbackFor = Exception.class)
77 public boolean customPoints(TempPoints tempPoints) {
78 Long memberId = tempPoints.getMemberId();
79 // 1.判断可用积分是否够用
80 boolean b = this.checkAvailablePoints(tempPoints);
81 if (b) {
82 // 当前可用总积分
83 long currentPoints = this.findAvailablePointsByMemberId(memberId);
84 // 1.可用积分表,按照过期时间进行升序排列
85 List<PointsAvailableDTO> pointsAvailableDTOS = this.findByMemberIdOrderByExpireTime(tempPoints);
86 // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分
87 Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = this.customAvailablePoints(tempPoints, pointsAvailableDTOS);
88 // 3.添加积分明细
89 this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints,customAvailablePointsMap,currentPoints);
90 // 4.更新可用积分表,超过的删除,剩余的新增
91 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap,currentPoints);
92 // 4.获取即将过期的积分
93 long soonExpireTime = this.getSoonExpirePoints(memberId,tempPoints);
94 // 6.更新会员积分信息
95 this.freshMemberCurrentPoints(memberId,totalPoints,soonExpireTime);
96
97 return true;
98 }
99
100 return false;
101 }
102
103 /**
104 * 更新可用积分表
105 * @param customAvailablePointsMap
106 */
107 private long doFreshTrPointsAvailableByAvailablePointsMap(
108 Map<String, List<PointsAvailableDTO>> customAvailablePointsMap,long currentPoints) {
109
110 long totalCustomAvailablePoints = 0L;
111 if (customAvailablePointsMap != null) {
112 // 需要删除的
113 List<PointsAvailableDTO> pointsAvailableDTOS1 = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS);
114 if (!CollectionUtils.isEmpty(pointsAvailableDTOS1)) {
115 for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS1) {
116 totalCustomAvailablePoints = (totalCustomAvailablePoints+pointsAvailableDTO.getPoints());
117 this.pointsAvailableService.delete(pointsAvailableDTO.getId());
118 }
119 }
120
121 // 需要添加的
122 List<PointsAvailableDTO> pointsAvailableDTOS2 = customAvailablePointsMap.get(INSERT_AVAILABLE_POINTS);
123 if (!CollectionUtils.isEmpty(pointsAvailableDTOS2)) {
124 PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS2.get(0);
125 PointsAvailable pointsAvailable = new PointsAvailable();
126 BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailable);
127 pointsAvailable.setId(null);
128 pointsAvailable.setCode(String.valueOf(IdWorker.generator()));
129 this.pointsAvailableService.create(pointsAvailable);
130 }
131 }
132
133 return currentPoints - totalCustomAvailablePoints;
134 }
135
136 /**
137 * 优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分
138 * @param customAvailablePointsMap
139 */
140 private void doInsertTrPointsDetailByAvailablePointsMap(TempPoints tempPoints,
141 Map<String, List<PointsAvailableDTO>> customAvailablePointsMap,
142 long currentPoints) {
143 // 兑换的积分
144 Long points = tempPoints.getPoints();
145
146 List<PointsAvailableDTO> pointsAvailableDTOS = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS);
147
148 if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) {
149 PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS.get(0);
150 Long memberId = pointsAvailableDTO.getMemberId();
151
152 TempPoints tempPoints1 = new TempPoints();
153 BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1);
154 BeanUtils.copyProperties(tempPoints,tempPoints1);
155 tempPoints1.setPoints(-(Math.abs(points)));
156 this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints);
157 }
158 }
159
160 /**
161 * 消耗过期的积分
162 * @param tempPoints 需要消耗的积分
163 * @param pointsAvailableDTOS 可用积分列表
164 * @return List<PointsAvailableDTO> 已消耗的可用积分列表
165 */
166 private Map<String,List<PointsAvailableDTO>> customAvailablePoints(TempPoints tempPoints, List<PointsAvailableDTO> pointsAvailableDTOS) {
167 // 兑换的积分
168 Long points = tempPoints.getPoints();
169 Long points1_ = 0L;
170 List<PointsAvailableDTO> pointsAvailableDTOS1 = new ArrayList<>();
171 List<PointsAvailableDTO> pointsAvailableDTOS2 = new ArrayList<>();
172 Map<String,List<PointsAvailableDTO>> map = new HashMap<>();
173
174 for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) {
175 Long points1 = pointsAvailableDTO.getPoints();
176 points1_ = (points1_ + points1);
177
178 // 不够
179 if (points1_ < points) {
180 pointsAvailableDTOS1.add(pointsAvailableDTO);
181 continue;
182 }
183
184 // 刚好
185 if (points1_ == points) {
186 pointsAvailableDTOS1.add(pointsAvailableDTO);
187 break;
188 }
189
190 // 超了,拆分
191 if (points1_ > points) {
192
193 // 超过的
194 long beyond = points1_ - points;
195 // 新增
196 PointsAvailableDTO pointsAvailableDTO2 = new PointsAvailableDTO();
197 BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO2);
198 pointsAvailableDTO2.setPoints(beyond);
199 pointsAvailableDTOS2.add(pointsAvailableDTO2);
200
201 // 剩余的
202 long suit = points1 - beyond;
203 // 扣除
204 PointsAvailableDTO pointsAvailableDTO1 = new PointsAvailableDTO();
205 BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO1);
206 pointsAvailableDTO1.setPoints(suit);
207 pointsAvailableDTOS1.add(pointsAvailableDTO1);
208
209 break;
210 }
211
212 }
213
214 map.put(DELETE_AVAILABLE_POINTS,pointsAvailableDTOS1);
215 map.put(INSERT_AVAILABLE_POINTS,pointsAvailableDTOS2);
216
217 return map;
218 }
219
220 /**
221 * 可用积分表,按照过期时间进行升序排列
222 * @param tempPoints
223 * @return
224 */
225 private List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(TempPoints tempPoints) {
226 return this.pointsAvailableService.findByMemberIdOrderByExpireTime(tempPoints.getMemberId());
227 }
228
229 /**
230 * 检查当前用户可用积分是否足够
231 * @param tempPoints
232 * @return true : 满足 false: 不满足
233 */
234 private boolean checkAvailablePoints(TempPoints tempPoints) {
235 Long memberId = tempPoints.getMemberId();
236 // 可用积分
237 long currentPoints = this.findAvailablePointsByMemberId(memberId);
238 long points1 = tempPoints.getPoints();
239 if (currentPoints > 0 && points1 > 0 && (currentPoints - Math.abs(points1) >= 0)) {
240 return true;
241 }
242 return false;
243 }
244
245 /**
246 * 积分发放,基于已获得的权益
247 *
248 * @param tempPointsList 已获得的权益
249 */
250 @Override
251 @Transactional(rollbackFor = Exception.class)
252 public void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList){
253 for (TempPoints tempPoints : tempPointsList){
254 this.refresh(tempPoints);
255 }
256 }
257
258 /**
259 * 定时清理过期的可用积分
260 */
261 @Override
262 public void cleanInvalidAvailablePoints() {
263 // 获取已过期的积分
264 List<PointsAvailableDTO> pointsAvailableDTOS = pointsAvailableService.findByExpireTimeBefore(TimestampUtil.now());
265 if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) {
266 // 添加积分明细 uc_points_detail
267 this.doCreatePointsDetail(pointsAvailableDTOS);
268 // 删除已过期的积分
269 this.doDeleteInvalidAvailablePoints(pointsAvailableDTOS);
270 }
271 }
272
273 /**
274 *
275 * @param pointsAvailableDTOS
276 */
277 private void doDeleteInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) {
278 List<Long> collect = pointsAvailableDTOS.stream().map(pointsAvailableDTO -> pointsAvailableDTO.getId()).collect(Collectors.toList());
279 this.pointsAvailableService.deleteBatchByIds(collect);
280 }
281
282 /**
283 *
284 * @param pointsAvailableDTOS
285 */
286 private void doCreatePointsDetail(List<PointsAvailableDTO> pointsAvailableDTOS) {
287
288 //1.获取原始积分
289 for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) {
290
291 Long memberId = pointsAvailableDTO.getMemberId();
292 // 原始积分
293 long availablePoints = this.findAvailablePointsByMemberId(memberId);
294 // 过期积分
295 long l = pointsAvailableDTO.getPoints();
296 // 结果积分
297 long resultPoints = availablePoints - l;
298
299 PointsDetail pointsDetail = new PointsDetail();
300 BeanUtils.copyProperties(pointsAvailableDTO,pointsDetail);
301 pointsDetail.setCode(String.valueOf(IdWorker.generator()));
302 pointsDetail.setOriginalPoints(availablePoints);
303 pointsDetail.setResultPoints(resultPoints);
304 pointsDetail.setDescription("过期积分");
305 pointsDetail.setEvtType(99);
306 this.doInsertPointsDetail(pointsDetail);
307
308 long soonExpireTime = this.getSoonExpirePoints(memberId,null);
309 // 更新会员积分
310 this.freshMemberCurrentPoints(memberId,resultPoints,soonExpireTime);
311 }
312
313 }
314
315 /**
316 * 模板方法,提供更新积分的总体流程
317 *
318 * @param tempPoints 积分
319 */
320 private void refresh(TempPoints tempPoints) {
321 Long memberId = tempPoints.getMemberId();
322 // 1.可用总积分
323 long currentPoints = this.findAvailablePointsByMemberId(memberId);
324 // 2.添加积分明细,并计算总积分
325 long totalPoints = this.doInsertTrPointsDetail(memberId, tempPoints,currentPoints);
326 // 3.获取即将过期的积分
327 long soonExpireTime = this.getSoonExpirePoints(memberId,tempPoints);
328 // 4.更新会员的总积分
329 this.freshMemberCurrentPoints(memberId,totalPoints,soonExpireTime);
330 // 5.添加可用积分
331 this.doInsertTrPointsAvailable(tempPoints);
332 }
333
334 /**
335 * 获取即将过期的积分
336 * @param memberId
337 * @return
338 */
339 private long getSoonExpirePoints(Long memberId,TempPoints tempPoints) {
340 // 计算即将过期的天数
341 Integer factor = this.calculateExpireFactor(tempPoints);
342 if (Objects.isNull(factor)) {
343 factor = EXPIRE_FACTOR;
344 }
345
346 Long soonExpireTime = this.pointsAvailableService.findSoonExpireTime(memberId, factor);
347 return Objects.nonNull(soonExpireTime) ? soonExpireTime : 0L;
348 }
349
350 /**
351 * 如果过期时间和过期天数同时存在,则以过期时间为准
352 * @param tempPoints
353 * @return
354 */
355 private Integer calculateExpireFactor(TempPoints tempPoints) {
356 // TODO 计算过期的相对时间
357 return null;
358 }
359
360 /**
361 * 更新会员总积分
362 * @param memberId 会员Id
363 * @param currentPoints 当前总积分
364 * @param duePoints 即将过期的积分
365 */
366 private void freshMemberCurrentPoints(Long memberId, Long currentPoints,long duePoints){
367 Member member = new Member();
368 member.setId(memberId);
369 member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0);
370 member.setDuePoints(duePoints);
371 member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now()));
372 try {
373 this.memberOperationService.doUpdateMemberPoints(member);
374 } catch (Exception e){
375 throw e;
376 }
377 }
378
379 /**
380 * 计算当前总积分
381 * @param memberId 会员id
382 * @return
383 */
384 private long findAvailablePointsByMemberId(long memberId){
385 return this.pointsAvailableService.findAvailablePointsByMemberId(memberId);
386 }
387
388 /**
389 * 更新可用积分表
390 * @param tempPoints
391 */
392 private void doInsertTrPointsAvailable(TempPoints tempPoints){
393
394 PointsAvailable pointsAvailable = new PointsAvailable();
395 BeanUtils.copyProperties(tempPoints,pointsAvailable);
396 String description = pointsAvailable.getDescription();
397 pointsAvailable.setCode(String.valueOf(IdWorker.generator()));
398 pointsAvailable.setDescription(StringUtils.isEmpty(description)?"#":description);
399 Timestamp timestamp = tempPoints.getExpireTime();
400 if (Objects.nonNull(timestamp)) {
401 pointsAvailable.setExpireTime(timestamp);
402 }
403
404 // 添加可用积分记录
405 this.doInsertTrPointsAvailable(pointsAvailable);
406
407 }
408
409 /**
410 * 添加可用积分记录
411 * @param pointsAvailable 可用积分
412 */
413 private void doInsertTrPointsAvailable(PointsAvailable pointsAvailable) {
414 this.pointsAvailableService.create(pointsAvailable);
415 }
416
417 /**
418 * 添加积分明细
419 * @param memberId 会员Id
420 * @param tempPoints 积分
421 * @return Integer 总积分
422 */
423 private long doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long currentPoints){
424
425 PointsDetail pointsDetail = new PointsDetail();
426 BeanUtils.copyProperties(tempPoints,pointsDetail);
427
428 // 获取的积分
429 long rewardPoints = tempPoints.getPoints();
430 // 原始积分
431 long originalPoints = currentPoints;
432 // 总积分
433 long totalPoints = originalPoints + rewardPoints;
434
435 pointsDetail.setMemberId(memberId);
436 pointsDetail.setCode(String.valueOf(IdWorker.generator()));
437
438 pointsDetail.setOriginalPoints(originalPoints);
439 pointsDetail.setResultPoints(totalPoints);
440 String description = pointsDetail.getDescription();
441 if (StringUtils.isEmpty(description)) {
442 pointsDetail.setDescription("#");
443 }
444
445 // 保存积分流水
446 this.doInsertPointsDetail(pointsDetail);
447
448 return totalPoints;
449
450 }
451
452 /**
453 *
454 * @param pointsDetail
455 */
456 private void doInsertPointsDetail(PointsDetail pointsDetail){
457 this.pointsDetailService.create(pointsDetail);
458 }
459 }
1 package com.topdraw.business.process.service.impl;
2
3 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
4 import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService;
5 import com.topdraw.business.basicdata.rights.service.RightsService;
6 import com.topdraw.business.basicdata.rights.service.dto.RightsDTO;
7 import com.topdraw.business.process.service.CouponOperationService;
8 import com.topdraw.business.process.service.ExpOperationService;
9 import com.topdraw.business.process.service.PointsOperationService;
10 import com.topdraw.business.process.service.RightsOperationService;
11 import com.topdraw.business.process.domian.*;
12 import com.topdraw.util.TimestampUtil;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.BeanUtils;
16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
18 import org.springframework.stereotype.Service;
19 import org.springframework.util.CollectionUtils;
20
21 import javax.annotation.Resource;
22 import java.util.*;
23
24 /**
25 * 权益处理
26 *
27 * @author XiangHan
28 * @date 2021.10.23
29 */
30 @Service
31 public class RightsOperationServiceImpl implements RightsOperationService {
32
33 private static final Logger LOG = LoggerFactory.getLogger(RightsOperationServiceImpl.class);
34
35 @Autowired
36 RightsHistoryService rightsHistoryService;
37 @Autowired
38 CouponOperationService couponOperationService;
39 @Autowired
40 RightsService rightsService;
41 @Autowired
42 ExpOperationService expOperationService;
43 @Autowired
44 PointsOperationService pointsOperationService;
45
46 @Resource(name = "executorTask")
47 ThreadPoolTaskExecutor threadPoolTaskExecutor;
48
49 /**
50 * 系统手动发放
51 * 实现步骤:
52 * 1.当前权益只有实体券
53 * @param rightsList
54 */
55 @Override
56 public void grantRightsByManual(List<RightsHistory> rightsList) {
57 // 1.权益区分
58 Map<RightType,Object> tempRightsMap = this.distinguishRight(rightsList);
59 // 2.权益下发
60 this.refresh(tempRightsMap);
61 // 3.保存权益历史
62 this.doInsertTrRightHistory(rightsList);
63 }
64
65 /**
66 * 权益发放
67 * @param tempRightsMap 权益类型
68 */
69 @Override
70 public void grantRights(Map<RightType, Object> tempRightsMap) {
71 // 1.权益下发
72 this.refresh(tempRightsMap);
73 // 2.创建权益历史对象
74 List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap);
75 // 3.保存权益历史
76 this.doInsertTrRightHistory(rightsList);
77 }
78
79
80 /**
81 *
82 * @param tempRightsMap
83 * @return
84 */
85 private List<RightsHistory> getRightHistory(Map<RightType, Object> tempRightsMap) {
86 List<TempRights> values = (List<TempRights>)tempRightsMap.get(RightType.RIGHTS);
87 List<RightsHistory> rightsHistoryList = new ArrayList<>();
88
89 values.forEach(value -> {
90 RightsHistory rightsHistory = new RightsHistory();
91 rightsHistory.setSendTime(TimestampUtil.now());
92 rightsHistory.setRightsId(value.getId());
93 rightsHistory.setMemberId(value.getMemberId());
94 rightsHistory.setExpireTime(value.getExpireTime());
95 rightsHistoryList.add(rightsHistory);
96 });
97
98 return rightsHistoryList;
99 }
100
101
102 /**
103 * 成长值发放,基于已获得的权益
104 * @param tempExpList 权益列表
105 */
106 private void grantExp(List<TempExp> tempExpList) {
107 if (!CollectionUtils.isEmpty(tempExpList))
108 this.expOperationService.grantPointsThroughTempExp(tempExpList);
109 }
110
111
112 /**
113 * 发放积分,基于已获得的权益
114 *
115 * @param tempPointsList 权益列表
116 */
117 private void grantPoint(List<TempPoints> tempPointsList) {
118 if (!CollectionUtils.isEmpty(tempPointsList))
119 this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList);
120 }
121
122
123 /**
124 * 发放优惠券,基于已获得的权益
125 *
126 * @param tempCouponList 优惠券
127 */
128 private void grantCoupon(List<TempCoupon> tempCouponList) {
129 // 发放优惠券
130 if (!CollectionUtils.isEmpty(tempCouponList))
131 this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList);
132 }
133
134
135 /**
136 * 权益发放
137 * @param tempRightsMap
138 */
139 private void refresh(Map<RightType, Object> tempRightsMap) {
140 /*threadPoolTaskExecutor.execute(()->{
141 this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS));
142 });
143 threadPoolTaskExecutor.execute(()->{
144 this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP));
145 });
146 threadPoolTaskExecutor.execute(()->{
147 this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON));
148 });*/
149
150 this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS));
151 this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP));
152 this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON));
153
154 }
155
156 /**
157 * 区分权益
158 * @param rightsList
159 * @return
160 */
161 private Map<RightType, Object> distinguishRight(List<RightsHistory> rightsList) {
162
163 Map<RightType,Object> map = new HashMap<>();
164
165 // 优惠券
166 List<TempCoupon> tempCouponList = new ArrayList<>();
167 for (RightsHistory right : rightsList) {
168 Long rightId = right.getRightsId();
169 Long memberId = right.getMemberId();
170 Long userId = right.getUserId();
171 // 权益类型
172 RightsDTO rightsDTO = this.getRights(rightId);
173 Integer type = rightsDTO.getType();
174 // 优惠券
175 if (type == 1) {
176 TempCoupon tempCoupon = new TempCoupon();
177 tempCoupon.setId(rightId);
178 tempCoupon.setMemberId(memberId);
179 tempCoupon.setUserId(userId);
180 tempCoupon.setRightsAmount(1);
181 tempCoupon.setRightsSendStrategy(0);
182 tempCouponList.add(tempCoupon);
183 }
184 }
185
186 // TODO 其他
187
188 // 优惠券
189 map.put(RightType.COUPON,tempCouponList);
190
191 return map;
192 }
193
194 /**
195 * 权益详情
196 * @param rightsId
197 * @return
198 */
199 private RightsDTO getRights(Long rightsId) {
200 RightsDTO rightsDTO = this.rightsService.findById(rightsId);
201 return rightsDTO;
202 }
203
204
205 /**
206 * 添加权益领取记录
207 * @param rightsHistories
208 */
209 private void doInsertTrRightHistory(List<RightsHistory> rightsHistories) {
210 if (!CollectionUtils.isEmpty(rightsHistories)) {
211
212 for (RightsHistory rightsHistory : rightsHistories) {
213 rightsHistory.setSendTime(TimestampUtil.now());
214 this.rightsHistoryService.create(rightsHistory);
215 }
216
217 }
218
219 }
220
221 }
1 package com.topdraw.business.process.service.impl;
2
3 public class TaskDealHandler {
4 }
1 package com.topdraw.business.process.service.impl;
2
3 import com.alibaba.fastjson.JSONObject;
4 import com.topdraw.business.basicdata.rights.constant.RightsType;
5 import com.topdraw.business.basicdata.rights.service.RightsService;
6 import com.topdraw.business.basicdata.rights.service.dto.RightsDTO;
7 import com.topdraw.business.basicdata.task.progress.domain.TrTaskProgress;
8 import com.topdraw.business.basicdata.task.progress.service.TrTaskProgressService;
9 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressDTO;
10 import com.topdraw.business.basicdata.task.progress.service.dto.TrTaskProgressQueryCriteria;
11 import com.topdraw.business.process.service.RightsOperationService;
12 import com.topdraw.business.process.service.TaskDealService;
13 import com.topdraw.business.process.service.TaskOperationService;
14 import com.topdraw.business.basicdata.member.service.MemberService;
15 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
16 import com.topdraw.business.basicdata.task.domain.Task;
17 import com.topdraw.business.basicdata.task.service.TaskService;
18 import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
19 import com.topdraw.business.basicdata.task.template.service.TaskTemplateService;
20 import com.topdraw.business.process.domian.*;
21 import com.topdraw.module.mq.DataSyncMsg;
22 import com.topdraw.module.mq.EventType;
23 import com.topdraw.util.*;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.BeanUtils;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
29 import org.springframework.stereotype.Service;
30 import org.springframework.util.Assert;
31 import org.springframework.util.CollectionUtils;
32 import org.springframework.util.StringUtils;
33
34 import javax.annotation.Resource;
35 import java.sql.Timestamp;
36 import java.util.*;
37 import java.util.stream.Collectors;
38
39 /**
40 * 任务处理
41 *
42 * @author XiangHan
43 * @date 2021.10.23
44 */
45 @Service
46 public class TaskOperationServiceImpl implements TaskOperationService {
47
48 private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class);
49
50 @Autowired
51 private TaskService taskService;
52 @Autowired
53 private MemberService memberService;
54 @Autowired
55 private RightsService rightsService;
56 @Autowired
57 private TaskTemplateService taskTemplateService;
58 @Autowired
59 private RightsOperationService rightsOperationService;
60 @Autowired
61 private TrTaskProgressService trTaskProgressService;
62
63 private static final Integer POINTS_TYPE_RANDOM = 1;
64 private static final Integer POINTS_MIN = 1;
65
66 private static final Integer TASK_FINISH_STATUS = 1;
67
68 @Resource(name = "executorTask")
69 ThreadPoolTaskExecutor threadPoolTaskExecutor;
70
71 @Override
72 public void dealTask(String content) {
73
74 long l = System.currentTimeMillis();
75
76 DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class);
77
78 String eventType = dataSyncMsg.getEventType();
79 DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg();
80
81 Long memberId = msgData.getMemberId();
82
83 // 1.通过任务标识获取任务模板
84 TaskTemplate taskTemplate = this.getTaskTemplate(eventType);
85 // 2.解析模板参数
86 Map<String,Object> paramMap = this.parseTaskTemplateParam(taskTemplate);
87 // 3.通过任务模板获取对应的任务列表
88 List<Task> taskList = this.loadListTaskByTaskTemplate(taskTemplate,paramMap);
89 // 4.判断当前用户是否满足任务完成条件
90 boolean checkResult = this.checkTaskCompletion(memberId,taskList);
91 if (checkResult) {
92 // 4.权益区分(积分、权益、成长值)
93 Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData);
94 // 5.权益发放
95 this.grantRight(tempRightsMap);
96 }
97
98 long r = System.currentTimeMillis();
99 LOG.info("总耗时======>>>>>" + (r-l));
100 }
101
102 /**
103 * 解析模板参数
104 * @param taskTemplate
105 * @return
106 */
107 private Map<String, Object> parseTaskTemplateParam(TaskTemplate taskTemplate) {
108 if (Objects.nonNull(taskTemplate)) {
109 String params = taskTemplate.getParams();
110 if (!StringUtils.isEmpty(params)) {
111 Map paramMap = JSONObject.parseObject(params,Map.class);
112 return paramMap;
113 }
114 }
115 return null;
116 }
117
118 /**
119 * 保存任务的完成情况
120 */
121 private void doRefreshTrTaskProcess(TrTaskProgress resources) {
122 Long id = resources.getId();
123 if (Objects.nonNull(id)) {
124 resources.setUpdateTime(TimestampUtil.now());
125 this.trTaskProgressService.update(resources);
126 } else {
127 this.trTaskProgressService.create(resources);
128 }
129 }
130
131 /**
132 * 权益发放
133 * @param tempRightsMap 会员id
134 */
135 private void grantRight(Map<RightType,Object> tempRightsMap) {
136 this.rightsOperationService.grantRights(tempRightsMap);
137 }
138
139 /**
140 * 权益区分
141 *
142 * @param taskList 任务列表
143 */
144 private Map<RightType,Object> distinguishRight(Long memberId,List<Task> taskList,DataSyncMsg.MsgData msgData) {
145
146 Map<RightType,Object> map = new HashMap<>();
147
148 // 区分权益类型(成长值(reward_exp)、积分(reward_points)、实体券),并发放权益
149 for (Task task : taskList) {
150
151 // 积分
152 List<TempPoints> tempPointsList = this.getTempPoints(memberId,msgData,task);
153 map.put(RightType.POINTS,tempPointsList);
154
155 // 成长值
156 List<TempExp> tempExpList = this.getTempExp(memberId,msgData,task);
157 map.put(RightType.EXP,tempExpList);
158
159 // 权益
160 map = this.getTempRight(memberId,task,map);
161
162 }
163
164 return map;
165
166 }
167
168
169 /**
170 * 创建权益
171 * @param memberId
172 * @param rightsId
173 * @param rightsAmount
174 * @param expireTime
175 * @return
176 */
177 private TempRights tmpRightsBuild(Long memberId ,Long rightsId, Integer rightsAmount,Long expireTime){
178 TempRights tempRights = new TempRights();
179 tempRights.setMemberId(memberId);
180 tempRights.setRightsAmount(rightsAmount);
181 tempRights.setId(rightsId);
182 if (Objects.nonNull(expireTime))
183 tempRights.setExpireTime(TimestampUtil.long2Timestamp(expireTime));
184 return tempRights;
185 }
186
187
188 /**
189 * 优惠券
190 * @param memberId
191 * @param rightsId
192 * @param rightsAmount
193 * @param rightsSendStrategy
194 * @return
195 */
196 private TempCoupon tempCouponBuild(Long memberId ,Long rightsId, Integer rightsAmount,Integer rightsSendStrategy){
197 TempCoupon tempCoupon = new TempCoupon();
198 tempCoupon.setMemberId(memberId);
199 tempCoupon.setId(rightsId);
200 tempCoupon.setRightsAmount(rightsAmount);
201 tempCoupon.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy);
202 return tempCoupon;
203 }
204
205
206
207 /**
208 * 权益1
209 * @param task
210 * @return
211 */
212 private Map<RightType,Object> getTempRight(Long memberId , Task task,Map<RightType,Object> map) {
213 // 优惠券
214 List<TempCoupon> tempCouponList = new ArrayList<>();
215 // 权益列表,用以保存权益记录
216 List<TempRights> rightsList = new ArrayList<>();
217 // 权益1
218 Long rights1Id = task.getRightsId();
219 if (Objects.nonNull(rights1Id)) {
220 // 权益详情
221 RightsDTO rightsDTO = this.getRight(rights1Id);
222 // 领取的权益数量
223 Integer rights1Amount = task.getRightsAmount();
224 // TODO 权益1发放的策略
225 Integer rightsSendStrategy = task.getRightsSendStrategy();
226
227 if (Objects.nonNull(rightsDTO)){
228 // 用以保存权益历史
229 Long expireTime = rightsDTO.getExpireTime();
230 TempRights tempRights = this.tmpRightsBuild(memberId,rights1Id,rights1Amount,expireTime);
231 rightsList.add(tempRights);
232
233 // 权益类型
234 Integer type = rightsDTO.getType();
235 switch (type) {
236 case 1:
237 // 优惠券
238 TempCoupon tempCoupon = this.tempCouponBuild(memberId,rights1Id,rights1Amount,rightsSendStrategy);
239 tempCouponList.add(tempCoupon);
240 break;
241 default:
242 break;
243 }
244 }
245 }
246
247 // 权益2
248 Long rights2Id = task.getRights2Id();
249 if (Objects.nonNull(rights2Id)) {
250
251 // 权益详情
252 RightsDTO rightsDTO = this.getRight(rights2Id);
253
254 Integer rights2Amount = task.getRights2Amount();
255 // TODO 权益2发放的策略
256 Integer rightsSendStrategy = task.getRightsSendStrategy();
257
258 if (Objects.nonNull(rightsDTO)) {
259 // 用以保存权益历史
260 Long expireTime = rightsDTO.getExpireTime();
261 TempRights tempRights = this.tmpRightsBuild(memberId,rights2Id,rights2Amount,expireTime);
262 rightsList.add(tempRights);
263
264 // 权益类型
265 Integer type = rightsDTO.getType();
266 switch (type) {
267 case 1:
268 // 优惠券
269 TempCoupon tempCoupon = this.tempCouponBuild(memberId,rights2Id,rights2Amount,rightsSendStrategy);
270 tempCouponList.add(tempCoupon);
271 break;
272 default:
273 break;
274 }
275
276 }
277 }
278
279 // 权益3
280 Long rights3Id = task.getRights3Id();
281 if (Objects.nonNull(rights3Id)) {
282
283 // 权益详情
284 RightsDTO rightsDTO = this.getRight(rights3Id);
285
286 Integer rights3Amount = task.getRights3Amount();
287 // TODO 权益3发放的策略
288 Integer rightsSendStrategy = task.getRightsSendStrategy();
289
290 if (Objects.nonNull(rightsDTO)){
291 // 用以保存权益历史
292 Long expireTime = rightsDTO.getExpireTime();
293 TempRights tempRights = this.tmpRightsBuild(memberId,rights3Id,rights3Amount,expireTime);
294 rightsList.add(tempRights);
295
296 // 权益类型
297 Integer type = rightsDTO.getType();
298 switch (type) {
299 case 1:
300 // 优惠券
301 TempCoupon tempCoupon = this.tempCouponBuild(memberId,rights3Id,rights3Amount,rightsSendStrategy);
302 tempCouponList.add(tempCoupon);
303 break;
304 default:
305 break;
306 }
307 }
308 }
309 // 优惠券
310 map.put(RightType.COUPON,tempCouponList);
311 map.put(RightType.RIGHTS,rightsList);
312 return map;
313 }
314
315 /**
316 *
317 * @param rightsId
318 * @return
319 */
320 private Integer getRightType(Long rightsId) {
321 RightsDTO rightsDTO = this.getRight(rightsId);
322 return Objects.nonNull(rightsDTO) ? rightsDTO.getType() : -999;
323 }
324
325 /**
326 *
327 * @param rightsId
328 * @return
329 */
330 private RightsDTO getRight(Long rightsId) {
331 RightsDTO rightsDTO = this.rightsService.findById(rightsId);
332 return rightsDTO;
333 }
334
335 /**
336 * 成长值
337 * @param task
338 * @return
339 */
340 private List<TempExp> getTempExp(Long memberId , DataSyncMsg.MsgData msgData,Task task) {
341 TempExp tempExp = new TempExp();
342 tempExp.setMemberId(memberId);
343 tempExp.setAppCode(msgData.getAppCode());
344 tempExp.setMemberId(msgData.getMemberId());
345 tempExp.setItemId(msgData.getItemId());
346 tempExp.setAccountId(msgData.getAccountId());
347 tempExp.setRewardExp(task.getRewardExp());
348 tempExp.setDeviceType(msgData.getDeviceType());
349 tempExp.setEvtType(msgData.getEvent());
350 tempExp.setOrderId(msgData.getOrderId());
351 tempExp.setMediaId(msgData.getMediaId());
352 tempExp.setActivityId(msgData.getOrderId());
353 Integer rightsSendStrategy = task.getRightsSendStrategy();
354 tempExp.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy);
355 return Arrays.asList(tempExp);
356
357 }
358
359 /**
360 * 积分
361 * @param task
362 * @return
363 */
364 private List<TempPoints> getTempPoints(Long memberId,DataSyncMsg.MsgData msgData,Task task) {
365 // 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值
366 Long rewardPoints = task.getRewardPoints();
367 // 过期时间
368 Long rewardPointsExpireTime = task.getRewardPointsExpireTime();
369 Timestamp expireTime = task.getExpireTime();
370 // 积分类型(0:定值、1:随机)
371 Integer pointsType = task.getPointsType();
372 // 随机积分的最大值
373 Integer rewardMaxPoints = task.getRewardMaxPoints();
374 if (Objects.nonNull(rewardPoints)) {
375 TempPoints tempPoints = new TempPoints();
376 // 如果积分是随机的,则取随机值
377 if (pointsType == POINTS_TYPE_RANDOM) {
378 rewardPoints = RandomUtil.getRandomPoints(POINTS_MIN,rewardMaxPoints);
379 }
380 tempPoints.setRewardPointsExpireTime(rewardPointsExpireTime);
381 tempPoints.setMemberId(memberId);
382 tempPoints.setAppCode(msgData.getAppCode());
383 tempPoints.setPoints(rewardPoints);
384 tempPoints.setPointsType(pointsType);
385 tempPoints.setDeviceType(msgData.getDeviceType());
386 tempPoints.setExpireTime(expireTime);
387 tempPoints.setOrderId(msgData.getOrderId());
388 tempPoints.setActivityId(msgData.getOrderId());
389 tempPoints.setMediaId(msgData.getMediaId());
390 tempPoints.setItemId(msgData.getItemId());
391 tempPoints.setAccountId(msgData.getAccountId());
392 tempPoints.setEvtType(msgData.getEvent());
393 Integer rightsSendStrategy = task.getRightsSendStrategy();
394 tempPoints.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy);
395 return Arrays.asList(tempPoints);
396 }
397
398 return null;
399 }
400
401 /**
402 * 判断任务是否完成
403 * 完成的条件如下:->
404 * 1. status 当前任务的状态 0:失效;1:生效
405 * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次
406 * 2. valid_time 任务生效时间
407 * 3. expire_time 任务失效时间
408 * 5. member_level 会员等级门槛(0表示无门槛)
409 * 6. member_vip 会员vip门槛(0表示没有门槛)
410 * 7. groups 能够获取该任务的用户分组,为空则都能获取
411 * 8. action_amount 行为量(完成此任务需要多少次相同行为的触发)
412 *
413 * @param taskList 任务列表
414 * @return boolean true:success false:fail
415 */
416 private boolean checkTaskCompletion(Long memberId , List<Task> taskList) {
417 if (!CollectionUtils.isEmpty(taskList)) {
418 // 会员信息
419 MemberDTO memberDTO = this.memberService.findById(memberId);
420 // 判断是否完成任务
421 CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> {
422
423 List<Task> taskStream = taskList1.stream().filter(task1 ->
424 task1.getStatus() == 1 &&
425 (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) <= 0) &&
426 (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) &&
427 (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) &&
428 (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) &&
429 (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() == 0 || task1.getMemberVip() == memberDTO1.getVip())
430 ).collect(Collectors.toList());
431
432 if (CollectionUtils.isEmpty(taskStream)) {
433 // 获取当前任务的完成情况
434 boolean result = this.checkAndRefreshTaskCompletion(memberId,taskStream);
435 return result;
436 }
437 return true;
438 };
439 return compareTaskCondition.compareCondition(memberDTO,taskList);
440 }
441
442 return false;
443 }
444
445 /**
446 * 检查并更新当前任务的完成情况
447 * @param memberId
448 * @param taskStream
449 * @return
450 */
451 private boolean checkAndRefreshTaskCompletion(Long memberId , List<Task> taskStream) {
452 TrTaskProgressQueryCriteria trTaskProgressQueryCriteria = new TrTaskProgressQueryCriteria();
453 trTaskProgressQueryCriteria.setMemberId(memberId);
454 String time1 = LocalDateTimeUtil.todayStart();
455 String time2 = LocalDateTimeUtil.todayEnd();;
456 trTaskProgressQueryCriteria.setCompletionTime(time1+","+time2);
457 ArrayList array = new ArrayList<>();
458 for (Task task : taskStream) {
459 TrTaskProgress trTaskProgress = new TrTaskProgress();
460
461 Long taskId = task.getId();
462 // 行为量(完成此任务需要多少次相同行为的触发)
463 Integer actionAmount = task.getActionAmount();
464 trTaskProgressQueryCriteria.setTaskId(taskId);
465 List<TrTaskProgressDTO> trTaskProgressDTOS = this.trTaskProgressService.queryAll(trTaskProgressQueryCriteria);
466
467 Long id = null;
468 Integer currentActionAmount = null;
469 Timestamp completionTime = null;
470 Integer status = 0;
471
472 // 行为量 1
473 if (actionAmount == 1) {
474
475 if (CollectionUtils.isEmpty(trTaskProgressDTOS)) {
476 currentActionAmount = 1;
477 completionTime = TimestampUtil.now();
478 status = TASK_FINISH_STATUS;
479 }
480
481 if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) {
482 // 此任务做过,但未完成
483 TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0);
484 Long id_ = trTaskProgressDTO.getId();
485 Integer status_ = trTaskProgressDTO.getStatus();
486 Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount();
487 if (status_ != 1 && Objects.isNull(trTaskProgressDTO.getCompletionTime())) {
488
489 id = id_;
490 currentActionAmount = 1;
491 completionTime = TimestampUtil.now();
492 status = TASK_FINISH_STATUS;
493
494 } else {
495
496 id = id_;
497 currentActionAmount = currentActionAmount_+1;
498
499 }
500
501 }
502 }
503
504 // 行为量不是1
505 if (actionAmount != 1) {
506
507 if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) {
508 // 此任务做过,但未完成
509 TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0);
510
511 Long id_ = trTaskProgressDTO.getId();
512 // 状态 0:未完成;1:已完成
513 Integer status_ = trTaskProgressDTO.getStatus();
514 Timestamp completionTime_ = trTaskProgressDTO.getCompletionTime();
515 Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount();
516 if (status_ != 1 && Objects.isNull(completionTime_) && actionAmount == currentActionAmount_+1) {
517 id = id_;
518 currentActionAmount = actionAmount;
519 completionTime = TimestampUtil.now();
520 status = TASK_FINISH_STATUS;
521 } else {
522 id = id_;
523 currentActionAmount = currentActionAmount_+1;
524 }
525
526 } else {
527 currentActionAmount = 1;
528 }
529
530 }
531
532 trTaskProgress.setId(id);
533 trTaskProgress.setCurrentActionAmount(currentActionAmount);
534 trTaskProgress.setCompletionTime(completionTime);
535 trTaskProgress.setStatus(status);
536 trTaskProgress.setTaskId(taskId);
537 trTaskProgress.setMemberId(memberId);
538 trTaskProgress.setTargetActionAmount(actionAmount);
539
540 // 更新任务完成情况
541 this.doRefreshTrTaskProcess(trTaskProgress);
542
543 if (status == 1) {
544 array.add(task);
545 }
546
547 }
548
549 if (CollectionUtils.isEmpty(array)) {
550 return true;
551 }
552
553
554 return false;
555 }
556
557
558
559 /**
560 * 获取任务模板对应的任务列表
561 *
562 * @param taskTemplate 任务模板
563 * @return List<task> 任务列表
564 */
565 private List<Task> loadListTaskByTaskTemplate(TaskTemplate taskTemplate,Map<String,Object> paramMap) {
566
567 if (Objects.nonNull(taskTemplate)) {
568 Long taskTemplateId = taskTemplate.getId();
569 return this.taskService.findByTemplateId(taskTemplateId);
570 }
571
572 return null;
573 }
574
575 /**
576 * 获取任务模板
577 * @param event 任务
578 * @return TaskTemplate 任务模板
579 */
580 private TaskTemplate getTaskTemplate(String event) {
581 return this.taskTemplateService.findByEvent(event);
582 }
583 }
1 package com.topdraw.business.process.service.impl;
2
3 import com.topdraw.business.process.service.TaskDealService;
4 import org.springframework.stereotype.Service;
5
6 @Service
7 public class UnsubscribeProductPackageTaskDealServiceImpl implements TaskDealService {
8 }
1 package com.topdraw.config;
2
3 public class LocalConstants {
4
5 // 小屏侧
6 public static final String ENV_MOBILE = "mobile";
7
8 // 大屏侧
9 public static final String ENV_VIS = "vis";
10
11 // 大屏类型
12 public static final int DEVICE_VIS = 1;
13
14 // 小屏类型
15 public static final int DEVICE_MOBILE = 2;
16 }
1 package com.topdraw.config;
2
3 import com.topdraw.utils.StringUtils;
4 import org.redisson.Redisson;
5 import org.redisson.api.RedissonClient;
6 import org.redisson.config.Config;
7 import org.springframework.beans.factory.annotation.Value;
8 import org.springframework.context.annotation.Bean;
9 import org.springframework.context.annotation.Configuration;
10
11 @Configuration
12 public class RedissonConfig {
13
14 // @Value("122.112.214.149")
15 @Value("${spring.redis.host}")
16 private String redisHost;
17
18 @Value("${spring.redis.port}")
19 private String port;
20
21 @Value("${spring.redis.password}")
22 private String password;
23
24 @Bean
25 public RedissonClient redisson(){
26 Config config = new Config();
27 // config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword("redis123");
28 if (StringUtils.isNotEmpty(password)) {
29 config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password);;
30 } else {
31 config.useSingleServer().setAddress("redis://"+redisHost+":"+port);
32 }
33 /* config.useClusterServers().addNodeAddress(
34 "redis://172.29.3.245:6375","redis://172.29.3.245:6376", "redis://172.29.3.245:6377",
35 "redis://172.29.3.245:6378","redis://172.29.3.245:6i379", "redis://172.29.3.245:6380")
36 .setPassword("a123456").setScanInterval(5000);*/
37 return Redisson.create(config);
38 }
39
40 }
1 package com.topdraw.config;
2
3
4 import org.springframework.scheduling.annotation.EnableScheduling;
5 import org.springframework.stereotype.Component;
6
7 @Component
8
9 public class ScheduledTaskConfig {
10 }
1 package com.topdraw.config;
2
3 import cn.hutool.core.util.ObjectUtil;
4 import org.springframework.beans.factory.annotation.Value;
5 import org.springframework.stereotype.Component;
6
7 @Component
8 public class ServiceEnvConfig {
9
10 // uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧
11 public static String UC_SERVICE_TYPE;
12
13 @Value("${uc.service.type:mobile}")
14 public void setUcServiceType(String ucServiceType) {
15 UC_SERVICE_TYPE = ucServiceType;
16 }
17
18 public static boolean isMobile() {
19 return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_MOBILE);
20 }
21
22 public static boolean isVis() {
23 return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_VIS);
24 }
25
26 }
1 package com.topdraw.config;
2
3 import lombok.extern.slf4j.Slf4j;
4 import org.springframework.beans.factory.annotation.Value;
5 import org.springframework.context.annotation.Bean;
6 import org.springframework.context.annotation.Configuration;
7 import org.springframework.context.annotation.PropertySource;
8 import org.springframework.scheduling.annotation.EnableAsync;
9 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
10 import org.springframework.stereotype.Component;
11
12 import java.util.concurrent.ThreadPoolExecutor;
13
14 @Configuration
15 @PropertySource(value = {"classpath:executor.properties"}, ignoreResourceNotFound=false, encoding="UTF-8")
16 @Slf4j
17 @EnableAsync
18 public class ThreadPoolTaskExecutorConfig {
19
20 @Value("${threadPoolExecutor.core_pool_size}")
21 private int corePoolSize;
22 @Value("${threadPoolExecutor.max_pool_size}")
23 private int maxPoolSize;
24 @Value("${threadPoolExecutor.queue_capacity}")
25 private int queueCapacity;
26 @Value("${threadPoolExecutor.name.prefix}")
27 private String namePrefix;
28 @Value("${threadPoolExecutor.keep_alive_seconds}")
29 private int keepAliveSeconds;
30
31 @Bean(value = "executorTask")
32 public ThreadPoolTaskExecutor executorTask(){
33 ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
34 // 核心线程数
35 executor.setCorePoolSize(corePoolSize);
36 // 最大线程数
37 executor.setMaxPoolSize(maxPoolSize);
38 // 任务队列大小
39 executor.setQueueCapacity(queueCapacity);
40 // 线程前缀名
41 executor.setThreadNamePrefix(namePrefix);
42 // 线程的空闲时间
43 executor.setKeepAliveSeconds(keepAliveSeconds);
44 // 拒绝策略
45 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
46 // 线程初始化
47 executor.initialize();
48 return executor;
49 }
50
51 }
1 package com.topdraw.mq.config;
2
3
4 import org.springframework.amqp.core.*;
5 import org.springframework.context.annotation.Bean;
6 import org.springframework.context.annotation.Configuration;
7
8 @Configuration
9 public class RabbitMqConfig {
10
11 /** 交换机--广播*/
12 public static final String UC_EXCHANGE_FANOUT = "uc.fanout";
13
14 /** 队列-- */
15 public static final String UC_QUEUE_FANOUT_IPTV = "uc.fanout.iptv";
16 public static final String UC_QUEUE_FANOUT_WEIXIN = "uc.fanout.weixin";
17
18
19 @Bean
20 FanoutExchange ucFanoutExchange(){
21 return ExchangeBuilder.fanoutExchange(UC_EXCHANGE_FANOUT).build();
22 }
23
24 @Bean
25 Queue ucFanoutQueueIptv(){
26 return new Queue(UC_QUEUE_FANOUT_IPTV);
27 }
28
29 @Bean
30 Queue ucFanoutQueueWeiXin(){
31 return new Queue(UC_QUEUE_FANOUT_WEIXIN);
32 }
33
34 @Bean
35 Binding fanoutExchangeBindingIptv(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueIptv){
36 return BindingBuilder.bind(ucFanoutQueueIptv).to(ucFanoutExchange);
37 }
38
39 @Bean
40 Binding fanoutExchangeBindingWeiXin(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueWeiXin){
41 return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange);
42 }
43
44
45
46 }
1 package com.topdraw.mq.domain;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
6
7 /**
8 *
9 */
10 @Data
11 @AllArgsConstructor
12 @NoArgsConstructor
13 public class TableOperationMsg {
14
15 // 数据表操作类型
16 private TableOperationType tableOperationType;
17
18 // 模型名称
19 private String entityName;
20
21 // 消息体
22 private String entityBody;
23
24 private String interfaceName;
25 private String methodName;
26 }
1 package com.topdraw.mq.domain;
2
3 // 数据表操作类型
4 public enum TableOperationType {
5
6 // 新增
7 ADD,INSERT,DOADD,DOINSERT,
8 // 修改
9 UPDATE,DOUPDATE,
10 // 删除
11 DELETE,DODELETE
12
13 }
1 package com.topdraw.mq.producer;
2
3 import com.topdraw.mq.config.RabbitMqConfig;
4 import lombok.extern.slf4j.Slf4j;
5 import org.springframework.amqp.core.AmqpTemplate;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Component;
8 import org.springframework.util.StringUtils;
9
10
11 @Component
12 @Slf4j
13 public class MessageProducer {
14
15
16 @Autowired
17 private AmqpTemplate amqpTemplate;
18
19 /**
20 * 广播
21 * @param msg
22 * @param exchangeName
23 * @author XiangHan
24 * @date 2021/9/7 11:10 上午
25 */
26 public void sendFanoutMessage(String msg,String exchangeName) {
27 if (StringUtils.isEmpty(exchangeName)) {
28 exchangeName = RabbitMqConfig.UC_EXCHANGE_FANOUT;
29 }
30 amqpTemplate.convertAndSend(exchangeName, "", msg);
31 log.info("send sendFanoutMessage msg || entityType: {} || msg:{} ", msg);
32 }
33
34 /**
35 * 广播
36 * @param msg
37 * @author XiangHan
38 * @date 2021/9/7 11:10 上午
39 */
40 public void sendFanoutMessage(String msg) {
41 this.sendFanoutMessage(msg,null);
42 }
43 }
1 package com.topdraw.resttemplate;
2
3 import com.alibaba.fastjson.JSONObject;
4 import com.topdraw.business.basicdata.member.address.domain.MemberAddress;
5 import com.topdraw.business.basicdata.member.domain.Member;
6 import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo;
7 import lombok.extern.slf4j.Slf4j;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.core.env.Environment;
10 import org.springframework.http.ResponseEntity;
11 import org.springframework.http.client.SimpleClientHttpRequestFactory;
12 import org.springframework.stereotype.Component;
13 import org.springframework.web.client.RestTemplate;
14
15 import javax.annotation.PostConstruct;
16 import java.util.Map;
17
18 @Slf4j
19 @Component
20 public class ApiUtil {
21
22 private static RestTemplate restTemplate;
23
24 private static String BASE_URL;
25
26 @Autowired
27 private Environment environment;
28
29 @PostConstruct
30 private void init() {
31 BASE_URL = environment.getProperty("api.baseUrl");
32 SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
33 // 设置连接超时
34 factory.setConnectTimeout(5000);
35 // 设置读取超时
36 factory.setReadTimeout(8000);
37 restTemplate = new RestTemplate(factory);
38 }
39
40 public static JSONObject getMemberInfo(Long memberId) {
41 JSONObject resultSet = null;
42 String url = BASE_URL + "/api/member/findById/" + memberId;
43 log.info("request uc : url is " + url + ", memberId is " + memberId);
44 ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
45 if (responseEntity.getStatusCode().is2xxSuccessful()) {
46 String entityBody = responseEntity.getBody();
47 JSONObject jsonObject = JSONObject.parseObject(entityBody);
48 if (jsonObject.getInteger("businessCode").equals(200)) {
49 resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0);
50 }
51 }
52 log.info("uc response: " + resultSet.toJSONString());
53 return resultSet;
54 }
55
56 public static String createMember(Member member) {
57 String entityBody = "";
58 String url = BASE_URL + "/api/member/create";
59 log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member));
60 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class);
61 if (responseEntity.getStatusCode().is2xxSuccessful()) {
62 entityBody = responseEntity.getBody();
63
64 }
65 return entityBody;
66 }
67
68 public static String updateMember(Member member) {
69 String entityBody = "";
70 String url = BASE_URL + "/api/member/update";
71 log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member));
72 restTemplate.put(url, member);
73
74 return entityBody;
75 }
76
77 public static String createMemberAddress(MemberAddress member) {
78 JSONObject resultSet = null;
79 String url = BASE_URL + "/api/MemberAddress/create";
80 log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member));
81 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class);
82 String entityBody = "";
83 if (responseEntity.getStatusCode().is2xxSuccessful()) {
84 entityBody = responseEntity.getBody();
85 }
86 log.info("uc response: " + entityBody);
87 return entityBody;
88 }
89
90 public static void updateMemberAddress(MemberAddress member) {
91 String url = BASE_URL + "/api/MemberAddress/update";
92 log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(member));
93 restTemplate.put(url, member);
94
95 }
96
97 public static void deleteMemberAddress(Long id) {
98 String url = BASE_URL + "/api/MemberAddress/delete/" + id;
99 log.info("request uc : url is " + url + ", memberId is " + id);
100 restTemplate.delete(url);
101
102 }
103
104 public static JSONObject getMemberProfile(Long memberId) {
105 JSONObject resultSet = null;
106 String url = BASE_URL + "/api/MemberRelatedInfo/getMemberRelatedInfos";
107 log.info("request uc : url is " + url + ", memberId is " + memberId);
108 ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
109 if (responseEntity.getStatusCode().is2xxSuccessful()) {
110 String entityBody = responseEntity.getBody();
111 JSONObject jsonObject = JSONObject.parseObject(entityBody);
112 if (jsonObject.getInteger("businessCode").equals(200)) {
113 resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0);
114 }
115 }
116 log.info("uc response: " + resultSet.toJSONString());
117 return resultSet;
118 }
119
120 public static String getMemberAddress(Map<String, Object> param) {
121 String entityBody = "";
122 String url = BASE_URL + "/api/MemberAddress/pageMemberAddress?page=" + param.get("page") + "&size=" + param.get("size") + "&memberId=" + param.get("memberId");
123 log.info("request uc : url is " + url + ", param is " + param);
124 ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
125 if (responseEntity.getStatusCode().is2xxSuccessful()) {
126 entityBody = responseEntity.getBody();
127 }
128 log.info("uc response: " + entityBody);
129 return entityBody;
130 }
131
132 public static String getMemberRelatedInfo(Map<String, Object> param) {
133 String entityBody = "";
134 String url = BASE_URL + "/api/MemberRelatedInfo/pageMemberRelatedInfos?page=" + param.get("page") + "&size=" + param.get("size") + "&memberId=" + param.get("memberId");
135 log.info("request uc : url is " + url + ", memberId is " + param);
136 ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
137 if (responseEntity.getStatusCode().is2xxSuccessful()) {
138 entityBody = responseEntity.getBody();
139 }
140 log.info("uc response: " + entityBody);
141 return entityBody;
142 }
143
144 public static void deleteMemberRelatedInfo(Long memberRelatedId) {
145 String url = BASE_URL + "/api/MemberRelatedInfo/delete/" + memberRelatedId;
146 log.info("request uc : url is " + url + ", memberId is " + memberRelatedId);
147 restTemplate.delete(url, String.class);
148 }
149
150 public static String addMemberRelatedInfo(MemberRelatedInfo resources) {
151 String entityBody = null;
152 String url = BASE_URL + "/api/MemberRelatedInfo/create";
153 log.info("request uc : url is " + url + ", memberRelatedId is " + com.alibaba.fastjson.JSONObject.toJSONString(resources));
154 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, resources, String.class);
155 if (responseEntity.getStatusCode().is2xxSuccessful()) {
156 entityBody = responseEntity.getBody();
157 // JSONObject jsonObject = JSONObject.parseObject(entityBody);
158 // if (jsonObject.getInteger("businessCode").equals(200)) {
159 // resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0);
160 // }
161 }
162 log.info("uc response: " + entityBody);
163 return entityBody;
164 }
165
166 public static String updateMemberRelatedInfo(MemberRelatedInfo resources) {
167 String resultSet = "";
168 String url = BASE_URL + "/api/MemberRelatedInfo/update";
169 log.info("request uc : url is " + url + ", memberRelatedId is " + com.alibaba.fastjson.JSONObject.toJSONString(resources));
170 restTemplate.put(url, resources);
171
172 return resultSet;
173 }
174 }
1 package com.topdraw.schedule;
2
3 import com.topdraw.business.basicdata.points.available.service.PointsAvailableService;
4 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
5 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria;
6 import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook;
7 import com.topdraw.business.basicdata.points.standingbook.service.PointsStandingBookService;
8 import com.topdraw.business.process.service.PointsOperationService;
9 import com.topdraw.util.DateUtil;
10 import lombok.extern.slf4j.Slf4j;
11 import org.aspectj.lang.annotation.After;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.scheduling.annotation.EnableScheduling;
14 import org.springframework.scheduling.annotation.Scheduled;
15 import org.springframework.stereotype.Component;
16 import org.springframework.util.CollectionUtils;
17
18 import java.sql.Timestamp;
19 import java.time.LocalDate;
20 import java.util.List;
21
22 /**
23 * 积分台账
24 */
25 @Component
26 @Slf4j
27 @EnableScheduling
28 public class ScheduledTask {
29
30 @Autowired
31 PointsOperationService pointsOperationService;
32
33 // @Scheduled(cron = "0/59 59 23 * * ? ")
34
35 /**
36 * 清理已过期的积分
37 */
38 @Scheduled(cron = "0 0/1 * * * ? ")
39 public void cleanValidAvailablePoints(){
40 this.pointsOperationService.cleanInvalidAvailablePoints();
41 }
42
43 }
1 package com.topdraw.util;
2
3 import java.time.LocalDateTime;
4 import java.util.Date;
5
6 public class DateUtil {
7
8 public static Date newDate(){
9 return new Date();
10 }
11
12 public static long currentTimestamp(){
13 return System.currentTimeMillis();
14 }
15
16
17 }
1 package com.topdraw.util;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5
6 import java.lang.management.ManagementFactory;
7 import java.net.InetAddress;
8 import java.net.NetworkInterface;
9
10 /**
11 * 生成订单ID, 雪花算法代码实现
12 */
13 public class IdWorker {
14 private static final Logger LOG = LoggerFactory.getLogger(IdWorker.class.getName());
15 // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
16 private final static long twepoch = 1288834974657L;
17 // 机器标识位数
18 private final static long workerIdBits = 5L;
19 // 数据中心标识位数
20 private final static long datacenterIdBits = 5L;
21 // 机器ID最大值
22 private final static long maxWorkerId = -1L ^ (-1L << workerIdBits);
23 // 数据中心ID最大值
24 private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
25 // 毫秒内自增位
26 private final static long sequenceBits = 12L;
27 // 机器ID偏左移12位
28 private final static long workerIdShift = sequenceBits;
29 // 数据中心ID左移17位
30 private final static long datacenterIdShift = sequenceBits + workerIdBits;
31 // 时间毫秒左移22位
32 private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
33
34 private final static long sequenceMask = -1L ^ (-1L << sequenceBits);
35 /* 上次生产id时间戳 */
36 private static long lastTimestamp = -1L;
37 // 0,并发控制
38 private long sequence = 0L;
39
40 private final long workerId;
41 // 数据标识id部分
42 private final long datacenterId;
43
44 public IdWorker(){
45 this.datacenterId = getDatacenterId(maxDatacenterId);
46 this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
47 }
48 /**
49 * @param workerId 工作机器ID
50 * @param datacenterId 序列号
51 */
52 public IdWorker(long workerId, long datacenterId) {
53 if (workerId > maxWorkerId || workerId < 0) {
54 throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
55 }
56 if (datacenterId > maxDatacenterId || datacenterId < 0) {
57 throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
58 }
59 this.workerId = workerId;
60 this.datacenterId = datacenterId;
61 }
62 /**
63 * 获取下一个ID
64 * @return
65 */
66 public synchronized long nextId() {
67 long timestamp = timeGen();
68 if (timestamp < lastTimestamp) {
69 throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
70 }
71
72 if (lastTimestamp == timestamp) {
73 // 当前毫秒内,则+1
74 sequence = (sequence + 1) & sequenceMask;
75 if (sequence == 0) {
76 // 当前毫秒内计数满了,则等待下一秒
77 timestamp = tilNextMillis(lastTimestamp);
78 }
79 } else {
80 sequence = 0L;
81 }
82 lastTimestamp = timestamp;
83 // ID偏移组合生成最终的ID,并返回ID
84 long nextId = ((timestamp - twepoch) << timestampLeftShift)
85 | (datacenterId << datacenterIdShift)
86 | (workerId << workerIdShift) | sequence;
87
88 return nextId;
89 }
90
91 private long tilNextMillis(final long lastTimestamp) {
92 long timestamp = this.timeGen();
93 while (timestamp <= lastTimestamp) {
94 timestamp = this.timeGen();
95 }
96 return timestamp;
97 }
98
99 private long timeGen() {
100 return System.currentTimeMillis();
101 }
102
103 /**
104 * 获取 maxWorkerId
105 */
106 protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) {
107 StringBuffer mpid = new StringBuffer();
108 mpid.append(datacenterId);
109 String name = ManagementFactory.getRuntimeMXBean().getName();
110 if (!name.isEmpty()) {
111 /*
112 * GET jvmPid
113 */
114 mpid.append(name.split("@")[0]);
115 }
116 /*
117 * MAC + PID 的 hashcode 获取16个低位
118 */
119 return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1);
120 }
121
122 /**
123 * 数据标识id部分
124 */
125 protected static long getDatacenterId(long maxDatacenterId) {
126 long id = 0L;
127 try {
128 InetAddress ip = InetAddress.getLocalHost();
129 NetworkInterface network = NetworkInterface.getByInetAddress(ip);
130 if (network == null) {
131 id = 1L;
132 } else {
133 byte[] mac = network.getHardwareAddress();
134 if (null == mac) {
135 return 1L;
136 }
137 id = ((0x000000FF & (long) mac[mac.length - 1])
138 | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
139 id = id % (maxDatacenterId + 1);
140 }
141 } catch (Exception e) {
142 LOG.warn(" getDatacenterId: " + e.getMessage());
143 }
144 return id;
145 }
146
147 public static long generator(){
148 IdWorker idWorker = new IdWorker();
149 return idWorker.nextId();
150 }
151
152 public static void main(String[] args) {
153 IdWorker idWorker = new IdWorker();
154 System.out.println(idWorker.nextId());
155 }
156 }
1 package com.topdraw.util;
2
3 import com.alibaba.fastjson.JSON;
4
5 public class JSONUtil<T> {
6
7 public static <T> T parseMsg2Object(String content , Class<T> clazz) {
8 T t = JSON.parseObject(content, clazz);
9 return t;
10 }
11
12 }
1 package com.topdraw.util;
2
3 import java.time.LocalDate;
4
5 public class LocalDateTimeUtil {
6
7
8 public static String todayStart() {
9 LocalDate now = LocalDate.now();
10
11 return now+" 00:00:00";
12 }
13
14 public static String todayEnd() {
15 LocalDate now = LocalDate.now();
16 return now+" 23:59:59";
17 }
18
19 public static void main(String[] args) {
20 String end = todayEnd();
21 System.out.println("end ==>> "+end);
22 String start = todayStart();
23 System.out.println("start ==>> "+start);
24 }
25 }
1 package com.topdraw.util;
2
3 import java.util.Random;
4
5 public class RandomUtil {
6
7 /**
8 * 获取随机积分
9 * @param max
10 * @param min
11 * @return
12 */
13 public static long getRandomPoints(Integer min,Integer max) {
14 Random random = new Random();
15 int s = random.nextInt(max)%(max-min+1) + min;
16 return s;
17 }
18
19 public static void main(String[] args) {
20 for (int i=0;i<30;i++) {
21 long randomPoints = getRandomPoints(1, 10);
22 System.out.println(randomPoints);
23 }
24
25 }
26
27 }
1 package com.topdraw.util;
2
3
4 import org.redisson.api.RLock;
5
6 public class RedissonUtil {
7
8 public static void lock(RLock rLock){
9 rLock.lock();
10 }
11
12
13 public static void unlock(RLock rLock){
14 if (rLock.isLocked() && rLock.isHeldByCurrentThread())
15 rLock.unlock();
16 }
17
18
19 }
1 package com.topdraw.util;
2
3 import java.sql.Timestamp;
4 import java.time.Instant;
5 import java.time.LocalDateTime;
6 import java.time.ZoneOffset;
7
8 public class TimestampUtil {
9
10 public static Timestamp now(){
11 return new Timestamp(System.currentTimeMillis());
12 }
13
14 public static Timestamp now(LocalDateTime localDateTime) {
15 long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).getEpochSecond();
16 return new Timestamp(epochSecond);
17 }
18
19 public static long localDateTime2Timestamp(LocalDateTime localDateTime){
20 long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond();
21 return epochSecond;
22 }
23
24 public static Timestamp long2Timestamp(long timestamp){
25 Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp));
26 return timestamp1;
27 }
28
29 public static long Timestamp2long(Timestamp timestamp){
30 return timestamp.toInstant().getEpochSecond();
31 }
32
33 public static void main(String[] args) {
34 LocalDateTime of = LocalDateTime.of(2021, 10, 28, 11, 00, 00);
35 long l = localDateTime2Timestamp(of);
36 // long l = 16342727230L;
37 Timestamp timestamp = long2Timestamp(l);
38 System.out.println(timestamp.toString());
39 }
40 }
1 ___________ .___
2 \__ ___/___ ______ __| _/___________ __ _ __
3 | | / _ \\____ \ / __ |\_ __ \__ \\ \/ \/ /
4 | |( <_> ) |_> > /_/ | | | \// __ \\ /
5 |____| \____/| __/\____ | |__| (____ /\/\_/
6 |__| \/ \/
7
8 :: UserCenter :: Spring Boot - ${spring-boot.version}
1 #配置数据源
2 spring:
3 datasource:
4 # 测试/演示库
5 url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
6 username: root
7 password: Tjlh@2017
8
9 # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
10 # url: jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
11 # username: root
12 # password: root
13 driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
14 #Druid
15 type: com.alibaba.druid.pool.DruidDataSource
16 druid:
17 # 初始化配置
18 initial-size: 3
19 # 最小连接数
20 min-idle: 3
21 # 最大连接数
22 max-active: 15
23 # 获取连接超时时间
24 max-wait: 5000
25 # 连接有效性检测时间
26 time-between-eviction-runs-millis: 90000
27 # 最大空闲时间
28 min-evictable-idle-time-millis: 1800000
29 test-while-idle: true
30 test-on-borrow: false
31 test-on-return: false
32
33 validation-query: select 1
34 # 配置监控统计拦截的filters
35 filters: stat
36 stat-view-servlet:
37 url-pattern: /druid/*
38 reset-enable: false
39
40 web-stat-filter:
41 url-pattern: /*
42 exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
43
44 #配置 Jpa
45 jpa:
46 hibernate:
47 # 生产环境设置成 none,避免程序运行时自动更新数据库结构
48 ddl-auto: none
49 servlet:
50 multipart:
51 file-size-threshold: 2KB
52 max-file-size: 100MB
53 max-request-size: 200MB
54 redis:
55 #数据库索引
56 database: 16
57 host: 122.112.214.149
58 # host: 139.196.4.234
59 port: 6379
60 password: redis123
61 # password:
62 #连接超时时间
63 timeout: 5000
64 rabbitmq:
65 host: 122.112.214.149 # rabbitmq的连接地址
66 #host: 139.196.192.242 # rabbitmq的连接地址
67 port: 5672 # rabbitmq的连接端口号
68 #virtual-host: /member_center # rabbitmq的虚拟host
69 #username: member_center # rabbitmq的用户名
70 #password: Tjlh@2021 # rabbitmq的密码
71 virtual-host: / # rabbitmq的虚拟host
72 username: guest # rabbitmq的用户名
73 password: guest # rabbitmq的密码
74 publisher-confirms: true #如果对异步消息需要回调必须设置为true
75
76 #jwt。依赖的common中有需要jwt的部分属性。
77 jwt:
78 header: Authorization
79 secret: mySecret
80 # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒
81 expiration: 7200000
82 # 在线用户key
83 online: online-token
84 # 验证码
85 codeKey: code-key
86 # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
87 detect: 3600000
88 # 续期时间,2小时,单位毫秒
89 renew: 7200000
90
91 #是否允许生成代码,生产环境设置为false
92 generator:
93 enabled: true
94
95 #是否开启 swagger-ui
96 swagger:
97 enabled: true
98
1 #配置数据源
2 spring:
3 datasource:
4 # 测试/演示库
5 url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
6 username: root
7 password: Tjlh@2017
8
9 # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
10 # url: jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
11 # username: root
12 # password: root
13 driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
14 #Druid
15 type: com.alibaba.druid.pool.DruidDataSource
16 druid:
17 # 初始化配置
18 initial-size: 3
19 # 最小连接数
20 min-idle: 3
21 # 最大连接数
22 max-active: 15
23 # 获取连接超时时间
24 max-wait: 5000
25 # 连接有效性检测时间
26 time-between-eviction-runs-millis: 90000
27 # 最大空闲时间
28 min-evictable-idle-time-millis: 1800000
29 test-while-idle: true
30 test-on-borrow: false
31 test-on-return: false
32
33 validation-query: select 1
34 # 配置监控统计拦截的filters
35 filters: stat
36 stat-view-servlet:
37 url-pattern: /druid/*
38 reset-enable: false
39
40 web-stat-filter:
41 url-pattern: /*
42 exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
43
44 #配置 Jpa
45 jpa:
46 hibernate:
47 # 生产环境设置成 none,避免程序运行时自动更新数据库结构
48 ddl-auto: none
49 servlet:
50 multipart:
51 file-size-threshold: 2KB
52 max-file-size: 100MB
53 max-request-size: 200MB
54 redis:
55 #数据库索引
56 database: 16
57 host: 122.112.214.149
58 # host: 139.196.4.234
59 port: 6379
60 password: redis123
61 # password:
62 #连接超时时间
63 timeout: 5000
64 rabbitmq:
65 host: 122.112.214.149 # rabbitmq的连接地址
66 #host: 139.196.192.242 # rabbitmq的连接地址
67 port: 5672 # rabbitmq的连接端口号
68 #virtual-host: /member_center # rabbitmq的虚拟host
69 #username: member_center # rabbitmq的用户名
70 #password: Tjlh@2021 # rabbitmq的密码
71 virtual-host: / # rabbitmq的虚拟host
72 username: guest # rabbitmq的用户名
73 password: guest # rabbitmq的密码
74 publisher-confirms: true #如果对异步消息需要回调必须设置为true
75
76 #jwt。依赖的common中有需要jwt的部分属性。
77 jwt:
78 header: Authorization
79 secret: mySecret
80 # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒
81 expiration: 7200000
82 # 在线用户key
83 online: online-token
84 # 验证码
85 codeKey: code-key
86 # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
87 detect: 3600000
88 # 续期时间,2小时,单位毫秒
89 renew: 7200000
90
91 #是否允许生成代码,生产环境设置为false
92 generator:
93 enabled: true
94
95 #是否开启 swagger-ui
96 swagger:
97 enabled: true
98
1 #配置数据源
2 spring:
3 datasource:
4 # 测试/演示库
5 url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
6 username: root
7 password: Tjlh@2017
8
9 # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
10 # url: jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
11 # username: root
12 # password: root
13 driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
14 #Druid
15 type: com.alibaba.druid.pool.DruidDataSource
16 druid:
17 # 初始化配置
18 initial-size: 3
19 # 最小连接数
20 min-idle: 3
21 # 最大连接数
22 max-active: 15
23 # 获取连接超时时间
24 max-wait: 5000
25 # 连接有效性检测时间
26 time-between-eviction-runs-millis: 90000
27 # 最大空闲时间
28 min-evictable-idle-time-millis: 1800000
29 test-while-idle: true
30 test-on-borrow: false
31 test-on-return: false
32
33 validation-query: select 1
34 # 配置监控统计拦截的filters
35 filters: stat
36 stat-view-servlet:
37 url-pattern: /druid/*
38 reset-enable: false
39
40 web-stat-filter:
41 url-pattern: /*
42 exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
43
44 #配置 Jpa
45 jpa:
46 hibernate:
47 # 生产环境设置成 none,避免程序运行时自动更新数据库结构
48 ddl-auto: none
49 servlet:
50 multipart:
51 file-size-threshold: 2KB
52 max-file-size: 100MB
53 max-request-size: 200MB
54 redis:
55 #数据库索引
56 database: 16
57 host: 122.112.214.149
58 # host: 139.196.4.234
59 port: 6379
60 password: redis123
61 # password:
62 #连接超时时间
63 timeout: 5000
64 rabbitmq:
65 host: 122.112.214.149 # rabbitmq的连接地址
66 #host: 139.196.192.242 # rabbitmq的连接地址
67 port: 5672 # rabbitmq的连接端口号
68 #virtual-host: /member_center # rabbitmq的虚拟host
69 #username: member_center # rabbitmq的用户名
70 #password: Tjlh@2021 # rabbitmq的密码
71 virtual-host: / # rabbitmq的虚拟host
72 username: guest # rabbitmq的用户名
73 password: guest # rabbitmq的密码
74 publisher-confirms: true #如果对异步消息需要回调必须设置为true
75
76 #jwt。依赖的common中有需要jwt的部分属性。
77 jwt:
78 header: Authorization
79 secret: mySecret
80 # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒
81 expiration: 7200000
82 # 在线用户key
83 online: online-token
84 # 验证码
85 codeKey: code-key
86 # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
87 detect: 3600000
88 # 续期时间,2小时,单位毫秒
89 renew: 7200000
90
91 #是否允许生成代码,生产环境设置为false
92 generator:
93 enabled: true
94
95 #是否开启 swagger-ui
96 swagger:
97 enabled: true
98
1 server:
2 port: 8447
3
4 spring:
5 application:
6 name: member-service
7 freemarker:
8 check-template-location: false
9 profiles:
10 active: test
11 jackson:
12 time-zone: GMT+8
13 data:
14 redis:
15 repositories:
16 enabled: false
17
18 #配置 Jpa
19 jpa:
20 properties:
21 hibernate:
22 dialect: org.hibernate.dialect.MySQL5InnoDBDialect
23 open-in-view: true
24
25
26 task:
27 pool:
28 # 核心线程池大小
29 core-pool-size: 10
30 # 最大线程数
31 max-pool-size: 30
32 # 活跃时间
33 keep-alive-seconds: 60
34 # 队列容量
35 queue-capacity: 50
36
37 #登录图形验证码有效时间/分钟
38 loginCode:
39 expiration: 2
40
41 #默认上传图片类型
42 default-image-type: -1
1 threadPoolExecutor.core_pool_size=5
2 threadPoolExecutor.max_pool_size=15
3 threadPoolExecutor.queue_capacity=10
4 threadPoolExecutor.name.prefix=asyncExecutor
5 threadPoolExecutor.keep_alive_seconds=2
...\ No newline at end of file ...\ No newline at end of file
1 #数据库类型转Java类型
2 tinyint=Integer
3 smallint=Integer
4 mediumint=Integer
5 int=Integer
6 integer=Integer
7
8 bigint=Long
9
10 float=Float
11
12 double=Double
13
14 decimal=BigDecimal
15
16 bit=Boolean
17
18 char=String
19 varchar=String
20 tinytext=String
21 text=String
22 mediumtext=String
23 longtext=String
24
25 date=Timestamp
26 datetime=Timestamp
27 timestamp=Timestamp
1 # If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
2 log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
3 log4jdbc.auto.load.popular.drivers=false
4 log4jdbc.drivers=com.mysql.cj.jdbc.Driver
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <configuration scan="true" scanPeriod="60 seconds" debug="false">
3
4 <contextName>UserCenter</contextName>
5 <!--定义参数,后面可以通过${app.name}使用-->
6 <property name="app.name" value="user-center"/>
7 <property name="log.path" value="./logs"/>
8 <property name="log.pattern" value="%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n"/>
9
10 <!--输出到控制台-->
11 <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
12 <!-- encoder 默认配置为PatternLayoutEncoder -->
13 <!--定义控制台输出格式-->
14 <encoder>
15 <pattern>%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %msg %n</pattern>
16 <charset>utf-8</charset>
17 </encoder>
18 </appender>
19
20 <!--获取比info级别高(包括info级别)但除error级别的日志-->
21 <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
22 <filter class="ch.qos.logback.classic.filter.LevelFilter">
23 <level>ERROR</level>
24 <onMatch>DENY</onMatch>
25 <onMismatch>ACCEPT</onMismatch>
26 </filter>
27 <encoder>
28 <pattern>${log.pattern}</pattern>
29 </encoder>
30 <!--滚动策略-->
31 <file>${log.path}/${app.name}-info.log</file>
32 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
33 <!--路径-->
34 <fileNamePattern>${log.path}/info/${app.name}-%d{yyyy-MM-dd}.log</fileNamePattern>
35 <maxHistory>30</maxHistory>
36 <totalSizeCap>10GB</totalSizeCap>
37 </rollingPolicy>
38 </appender>
39
40 <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
41 <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
42 <level>ERROR</level>
43 </filter>
44 <encoder>
45 <pattern>${log.pattern}</pattern>
46 </encoder>
47 <!--滚动策略-->
48 <file>${log.path}/${app.name}-error.log</file>
49 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
50 <!--路径-->
51 <fileNamePattern>${log.path}/error/${app.name}-%d{yyyy-MM-dd}.log</fileNamePattern>
52 <maxHistory>30</maxHistory>
53 <totalSizeCap>10GB</totalSizeCap>
54 </rollingPolicy>
55 </appender>
56
57
58 <!--普通日志输出到控制台-->
59 <root level="info">
60 <appender-ref ref="console" />
61 <appender-ref ref="info" />
62 <appender-ref ref="error" />
63 </root>
64
65
66 <!--监控sql日志输出 -->
67 <logger name="jdbc.sqlonly" level="INFO" additivity="false">
68 <appender-ref ref="console" />
69 <appender-ref ref="info" />
70 </logger>
71
72 <logger name="jdbc.resultset" level="ERROR" additivity="false">
73 <appender-ref ref="console" />
74 <appender-ref ref="info" />
75 </logger>
76
77 <!-- 如想看到表格数据,将OFF改为INFO -->
78 <logger name="jdbc.resultsettable" level="OFF" additivity="false">
79 <appender-ref ref="console" />
80 </logger>
81
82 <logger name="jdbc.connection" level="OFF" additivity="false">
83 <appender-ref ref="console" />
84 <appender-ref ref="info" />
85 </logger>
86
87 <logger name="jdbc.sqltiming" level="OFF" additivity="false">
88 <appender-ref ref="console" />
89 <appender-ref ref="info" />
90 </logger>
91
92 <logger name="jdbc.audit" level="OFF" additivity="false">
93 <appender-ref ref="console" />
94 <appender-ref ref="info" />
95 </logger>
96 </configuration>
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
5 <style>
6 @page {
7 margin: 0;
8 }
9 </style>
10 </head>
11 <body style="margin: 0px;
12 padding: 0px;
13 font: 100% SimSun, Microsoft YaHei, Times New Roman, Verdana, Arial, Helvetica, sans-serif;
14 color: #000;">
15 <div style="height: auto;
16 width: 820px;
17 min-width: 820px;
18 margin: 0 auto;
19 margin-top: 20px;
20 border: 1px solid #eee;">
21 <div style="padding: 10px;padding-bottom: 0px;">
22 <p style="margin-bottom: 10px;padding-bottom: 0px;">尊敬的用户,您好:</p>
23 <p style="text-indent: 2em; margin-bottom: 10px;">您正在申请邮箱验证,您的验证码为:</p>
24 <p style="text-align: center;
25 font-family: Times New Roman;
26 font-size: 22px;
27 color: #C60024;
28 padding: 20px 0px;
29 margin-bottom: 10px;
30 font-weight: bold;
31 background: #ebebeb;">${code}</p>
32 <div style="list-style: none;
33 margin-top: 22px;
34 maigin-bottom: 10px;
35 font-size: 14px;
36 color: #555;">
37 <p style="line-height: 12px;">Github:<a hover="color: #DA251D;" style="color: #999;" href="https://github.com/elunez/eladmin" target="_blank">https://github.com/elunez/eladmin</a></p>
38 </div>
39 <div class="foot-hr hr" style="margin: 0 auto;
40 z-index: 111;
41 width: 800px;
42 margin-top: 30px;
43 border-top: 1px solid #DA251D;">
44 </div>
45 <div style="text-align: center;
46 font-size: 12px;
47 padding: 20px 0px;
48 font-family: Microsoft YaHei;">
49 Copyright &copy;${.now?string("yyyy")} EL-ADMIN 后台管理系统 All Rights Reserved.
50 </div>
51
52 </div>
53 </div>
54 </body>
55 </html>
1 package ${package}.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import ${package}.domain.${className};
6 import ${package}.service.${className}Service;
7 import ${package}.service.dto.${className}QueryCriteria;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.data.domain.Pageable;
10 import org.springframework.http.HttpStatus;
11 import org.springframework.http.ResponseEntity;
12 import org.springframework.validation.annotation.Validated;
13 import org.springframework.web.bind.annotation.*;
14 import io.swagger.annotations.*;
15 import java.io.IOException;
16 import javax.servlet.http.HttpServletResponse;
17
18 /**
19 * @author ${author}
20 * @date ${date}
21 */
22 @Api(tags = "${className}管理")
23 @RestController
24 @RequestMapping("/api/${changeClassName}")
25 public class ${className}Controller {
26
27 @Autowired
28 private ${className}Service ${changeClassName}Service;
29
30 @GetMapping
31 @ApiOperation("查询${className}")
32 public ResultInfo get${className}s(${className}QueryCriteria criteria, Pageable pageable) {
33 return ResultInfo.successPage(${changeClassName}Service.queryAll(criteria,pageable));
34 }
35
36 @GetMapping(value = "/all")
37 @ApiOperation("查询所有${className}")
38 public ResultInfo get${className}s(${className}QueryCriteria criteria) {
39 return ResultInfo.success(${changeClassName}Service.queryAll(criteria));
40 }
41
42 @Log
43 @PostMapping
44 @ApiOperation("新增${className}")
45 public ResultInfo create(@Validated @RequestBody ${className} resources) {
46 ${changeClassName}Service.create(resources);
47 return ResultInfo.success();
48 }
49
50 @Log
51 @PutMapping
52 @ApiOperation("修改${className}")
53 public ResultInfo update(@Validated @RequestBody ${className} resources) {
54 ${changeClassName}Service.update(resources);
55 return ResultInfo.success();
56 }
57
58
59 @Log
60 @DeleteMapping(value = "/{${pkChangeColName}}")
61 @ApiOperation("删除${className}")
62 public ResultInfo delete(@PathVariable ${pkColumnType} ${pkChangeColName}) {
63 ${changeClassName}Service.delete(${pkChangeColName});
64 return ResultInfo.success();
65 }
66
67 <#if columns??>
68 <#list columns as column>
69 <#if column.columnName == 'code'>
70 @GetMapping(value = "/getByCode/{code}")
71 @ApiOperation(value = "根据标识查询")
72 public ResultInfo getByCode(@PathVariable String code) {
73 return ResultInfo.success(${changeClassName}Service.getByCode(code));
74 }
75 </#if>
76 </#list>
77 </#if>
78 }
1 package ${package}.service.dto;
2
3 import lombok.Data;
4 <#if hasTimestamp>
5 import java.sql.Timestamp;
6 </#if>
7 <#if hasBigDecimal>
8 import java.math.BigDecimal;
9 </#if>
10 import java.io.Serializable;
11 <#if !auto && pkColumnType = 'Long'>
12 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
13 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
14 </#if>
15
16
17 /**
18 * @author ${author}
19 * @date ${date}
20 */
21 @Data
22 public class ${className}DTO implements Serializable {
23 <#if columns??>
24 <#list columns as column>
25
26 <#if column.columnComment != ''>
27 // ${column.columnComment}
28 </#if>
29 <#if column.columnKey = 'PRI'>
30 <#if !auto && pkColumnType = 'Long'>
31 // 处理精度丢失问题
32 @JsonSerialize(using= ToStringSerializer.class)
33 </#if>
34 </#if>
35 private ${column.columnType} ${column.changeColumnName};
36 </#list>
37 </#if>
38 }
1 package ${package}.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 <#if hasTimestamp>
12 import java.sql.Timestamp;
13 </#if>
14 <#if hasBigDecimal>
15 import java.math.BigDecimal;
16 </#if>
17 <#if hasCode>
18 import java.util.UUID;
19 </#if>
20
21 import java.io.Serializable;
22
23 /**
24 * @author ${author}
25 * @date ${date}
26 */
27 @Entity
28 @Data
29 @EntityListeners(AuditingEntityListener.class)
30 @Accessors(chain = true)
31 @Table(name="${tableName}")
32 public class ${className} implements Serializable {
33 <#if columns??>
34 <#list columns as column>
35
36 <#if column.columnComment != ''>
37 // ${column.columnComment}
38 </#if>
39 <#if column.columnKey = 'PRI'>
40 @Id
41 <#if auto>
42 @GeneratedValue(strategy = GenerationType.IDENTITY)
43 </#if>
44 </#if>
45 <#if column.columnName == 'create_time'>
46 @CreatedDate
47 </#if>
48 <#if column.columnName == 'update_time'>
49 @LastModifiedDate
50 </#if>
51 @Column(name = "${column.columnName}"<#if column.columnKey = 'UNI'>,unique = true</#if><#if column.isNullable = 'NO' && column.columnKey != 'PRI'>, nullable = false</#if>)
52 private ${column.columnType} ${column.changeColumnName};
53 </#list>
54 </#if>
55
56 public void copy(${className} source){
57 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
58 }
59 }
1 package ${package}.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import ${package}.domain.${className};
5 import ${package}.service.dto.${className}DTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author ${author}
11 * @date ${date}
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface ${className}Mapper extends BaseMapper<${className}DTO, ${className}> {
15
16 }
1 package ${package}.service.dto;
2
3 import lombok.Data;
4 <#if queryHasTimestamp>
5 import java.sql.Timestamp;
6 </#if>
7 <#if queryHasBigDecimal>
8 import java.math.BigDecimal;
9 </#if>
10 <#if queryColumns??>
11 import com.topdraw.annotation.Query;
12 </#if>
13
14 /**
15 * @author ${author}
16 * @date ${date}
17 */
18 @Data
19 public class ${className}QueryCriteria{
20 <#if queryColumns??>
21 <#list queryColumns as column>
22
23 <#if column.columnQuery = '1'>
24 // 模糊
25 @Query(type = Query.Type.INNER_LIKE)
26 </#if>
27 <#if column.columnQuery = '2'>
28 // 精确
29 @Query
30 </#if>
31 private ${column.columnType} ${column.changeColumnName};
32 </#list>
33 </#if>
34 }
1 package ${package}.repository;
2
3 import ${package}.domain.${className};
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author ${author}
11 * @date ${date}
12 */
13 public interface ${className}Repository extends JpaRepository<${className}, ${pkColumnType}>, JpaSpecificationExecutor<${className}> {
14 <#if columns??>
15 <#list columns as column>
16 <#if column.columnKey = 'UNI'>
17
18 ${className} findBy${column.capitalColumnName}(${column.columnType} ${column.columnName});
19 </#if>
20 </#list>
21 </#if>
22
23 <#if columns??>
24 <#list columns as column>
25 <#if column.columnName == 'code'>
26 Optional<${className}> findFirstByCode(String code);
27 </#if>
28 </#list>
29 </#if>
30 }
1 package ${package}.service;
2
3 import ${package}.domain.${className};
4 import ${package}.service.dto.${className}DTO;
5 import ${package}.service.dto.${className}QueryCriteria;
6 import org.springframework.data.domain.Pageable;
7 import java.util.Map;
8 import java.util.List;
9 import java.io.IOException;
10 import javax.servlet.http.HttpServletResponse;
11
12 /**
13 * @author ${author}
14 * @date ${date}
15 */
16 public interface ${className}Service {
17
18 /**
19 * 查询数据分页
20 * @param criteria 条件参数
21 * @param pageable 分页参数
22 * @return Map<String,Object>
23 */
24 Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable);
25
26 /**
27 * 查询所有数据不分页
28 * @param criteria 条件参数
29 * @return List<${className}DTO>
30 */
31 List<${className}DTO> queryAll(${className}QueryCriteria criteria);
32
33 /**
34 * 根据ID查询
35 * @param ${pkChangeColName} ID
36 * @return ${className}DTO
37 */
38 ${className}DTO findById(${pkColumnType} ${pkChangeColName});
39
40 void create(${className} resources);
41
42 void update(${className} resources);
43
44 void delete(${pkColumnType} ${pkChangeColName});
45
46 <#if columns??>
47 <#list columns as column>
48 <#if column.columnName == 'code'>
49 /**
50 * Code校验
51 * @param code
52 * @return ${className}DTO
53 */
54 ${className}DTO getByCode(String code);
55 </#if>
56 </#list>
57 </#if>
58 }
1 package ${package}.service.impl;
2
3 import ${package}.domain.${className};
4 <#if columns??>
5 <#list columns as column>
6 <#if column.columnKey = 'UNI'>
7 <#if column_index = 1>
8 import com.topdraw.exception.EntityExistException;
9 </#if>
10 </#if>
11 </#list>
12 </#if>
13 import com.topdraw.utils.ValidationUtil;
14 import com.topdraw.utils.FileUtil;
15 import ${package}.repository.${className}Repository;
16 import ${package}.service.${className}Service;
17 import ${package}.service.dto.${className}DTO;
18 import ${package}.service.dto.${className}QueryCriteria;
19 import ${package}.service.mapper.${className}Mapper;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Service;
22 import org.springframework.transaction.annotation.Propagation;
23 import org.springframework.transaction.annotation.Transactional;
24 import org.springframework.dao.EmptyResultDataAccessException;
25 <#if !auto && pkColumnType = 'Long'>
26 import cn.hutool.core.lang.Snowflake;
27 import cn.hutool.core.util.IdUtil;
28 </#if>
29 <#if !auto && pkColumnType = 'String'>
30 import cn.hutool.core.util.IdUtil;
31 </#if>
32 import org.springframework.data.domain.Page;
33 import org.springframework.data.domain.Pageable;
34 import org.springframework.util.Assert;
35 import com.topdraw.utils.PageUtil;
36 import com.topdraw.utils.QueryHelp;
37 import com.topdraw.utils.StringUtils;
38
39 import java.util.List;
40 import java.util.Map;
41 import java.io.IOException;
42 import javax.servlet.http.HttpServletResponse;
43 import java.util.ArrayList;
44 import java.util.LinkedHashMap;
45
46 /**
47 * @author ${author}
48 * @date ${date}
49 */
50 @Service
51 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
52 public class ${className}ServiceImpl implements ${className}Service {
53
54 @Autowired
55 private ${className}Repository ${changeClassName}Repository;
56
57 @Autowired
58 private ${className}Mapper ${changeClassName}Mapper;
59
60 @Override
61 public Map<String, Object> queryAll(${className}QueryCriteria criteria, Pageable pageable) {
62 Page<${className}> page = ${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
63 return PageUtil.toPage(page.map(${changeClassName}Mapper::toDto));
64 }
65
66 @Override
67 public List<${className}DTO> queryAll(${className}QueryCriteria criteria) {
68 return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
69 }
70
71 @Override
72 public ${className}DTO findById(${pkColumnType} ${pkChangeColName}) {
73 ${className} ${changeClassName} = ${changeClassName}Repository.findById(${pkChangeColName}).orElseGet(${className}::new);
74 ValidationUtil.isNull(${changeClassName}.get${pkCapitalColName}(),"${className}","${pkChangeColName}",${pkChangeColName});
75 return ${changeClassName}Mapper.toDto(${changeClassName});
76 }
77
78 @Override
79 @Transactional(rollbackFor = Exception.class)
80 public void create(${className} resources) {
81 <#if !auto && pkColumnType = 'Long'>
82 Snowflake snowflake = IdUtil.createSnowflake(1, 1);
83 resources.set${pkCapitalColName}(snowflake.nextId());
84 </#if>
85 <#if !auto && pkColumnType = 'String'>
86 resources.set${pkCapitalColName}(IdUtil.simpleUUID());
87 </#if>
88 <#if columns??>
89 <#list columns as column>
90 <#if column.columnKey = 'UNI'>
91 if(${changeClassName}Repository.findBy${column.capitalColumnName}(resources.get${column.capitalColumnName}()) != null) {
92 throw new EntityExistException(${className}.class,"${column.columnName}",resources.get${column.capitalColumnName}());
93 }
94 </#if>
95 </#list>
96 </#if>
97 ${changeClassName}Repository.save(resources);
98 }
99
100 @Override
101 @Transactional(rollbackFor = Exception.class)
102 public void update(${className} resources) {
103 ${className} ${changeClassName} = ${changeClassName}Repository.findById(resources.get${pkCapitalColName}()).orElseGet(${className}::new);
104 ValidationUtil.isNull( ${changeClassName}.get${pkCapitalColName}(),"${className}","id",resources.get${pkCapitalColName}());
105 <#if columns??>
106 <#list columns as column>
107 <#if column.columnKey = 'UNI'>
108 <#if column_index = 1>
109 ${className} ${changeClassName}1 = null;
110 </#if>
111 ${changeClassName}1 = ${changeClassName}Repository.findBy${column.capitalColumnName}(resources.get${column.capitalColumnName}());
112 if(${changeClassName}1 != null && !${changeClassName}1.get${pkCapitalColName}().equals(${changeClassName}.get${pkCapitalColName}())){
113 throw new EntityExistException(${className}.class,"${column.columnName}",resources.get${column.capitalColumnName}());
114 }
115 </#if>
116 </#list>
117 </#if>
118 ${changeClassName}.copy(resources);
119 ${changeClassName}Repository.save(${changeClassName});
120 }
121
122 @Override
123 @Transactional(rollbackFor = Exception.class)
124 public void delete(${pkColumnType} ${pkChangeColName}) {
125 Assert.notNull(id, "The given id must not be null!");
126 ${className} ${changeClassName} = ${changeClassName}Repository.findById(id).orElseThrow(
127 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ${className}.class, id), 1));
128 ${changeClassName}Repository.delete(${changeClassName});
129 }
130
131
132 <#if columns??>
133 <#list columns as column>
134 <#if column.columnName == 'code'>
135 @Override
136 public ${className}DTO getByCode(String code) {
137 return StringUtils.isNotEmpty(code) ? ${changeClassName}Mapper.toDto(${changeClassName}Repository.findFirstByCode(code).orElseGet(${className}::new))
138 : new ${className}DTO();
139 }
140 </#if>
141 </#list>
142 </#if>
143 }
1 import request from '@/utils/request'
2
3 export function add(data) {
4 return request({
5 url: 'api/${changeClassName}',
6 method: 'post',
7 data
8 })
9 }
10
11 export function del(${pkChangeColName}) {
12 return request({
13 url: 'api/${changeClassName}/' + ${pkChangeColName},
14 method: 'delete'
15 })
16 }
17
18 export function edit(data) {
19 return request({
20 url: 'api/${changeClassName}',
21 method: 'put',
22 data
23 })
24 }
25
26 export function download${className}(params) {
27 return request({
28 url: 'api/${changeClassName}/download',
29 method: 'get',
30 params,
31 responseType: 'blob'
32 })
33 }
34
35 <#if columns??>
36 <#list columns as column>
37 <#if column.columnName == 'code'>
38 export function getByCode(code) {
39 return request({
40 url: 'api/${changeClassName}/getByCode/' + code,
41 method: 'get'
42 })
43 }
44 </#if>
45 </#list>
46 </#if>
1 <template>
2 <el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="960px" @closed="doClose">
3 <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px" style="padding: 30px;margin: -20px 0">
4 <el-row>
5 <#if columns??>
6 <#list columns as column>
7 <#if column.changeColumnName != '${pkChangeColName}'>
8 <#if column.columnName != 'images' && column.columnName != 'create_time' && column.columnName != 'update_time'>
9 <el-col :span="12">
10 <el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.isNullable =
11 'NO'>prop="${column.changeColumnName}"</#if>>
12 <#if column.columnName = 'code'>
13 <el-input v-model="form.${column.changeColumnName}" prop="code"/>
14 <#elseif column.columnType = 'Timestamp'>
15 <el-date-picker v-model="form.${column.changeColumnName}" type="datetime"/>
16 <#elseif column.columnName = 'image'>
17 <images-upload ref="upload" :limit="5" :image.sync="form.image" :images.sync="form.images" upload-entity="${changeClassName}" />
18 <#else>
19 <el-input v-model="form.${column.changeColumnName}"/>
20 </#if>
21 </el-form-item>
22 </el-col>
23 </#if>
24 </#if>
25 </#list>
26 </#if>
27 </el-row>
28 </el-form>
29 <div slot="footer" class="dialog-footer">
30 <el-button type="text" @click="cancel">取消</el-button>
31 <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
32 </div>
33 </el-dialog>
34 </template>
35
36 <script>
37 import { add, edit } from '@/api/${changeClassName}'
38 <#if columns??>
39 <#list columns as column>
40 <#if column.columnName == 'code'>
41 import { getByCode } from '@/api/${changeClassName}'
42 </#if>
43 </#list>
44 </#if>
45 import ImagesUpload from '@/components/ImagesUpload/index'
46 export default {
47 components: { ImagesUpload },
48 props: {
49 isAdd: {
50 type: Boolean,
51 required: true
52 },
53 dictMap: {
54 type: Object,
55 required: true
56 }
57 },
58 data() {
59 return {
60 loading: false, dialog: false,
61 form: {
62 <#if columns??>
63 <#list columns as column>
64 ${column.changeColumnName}: ''<#if column_has_next>,</#if>
65 </#list>
66 </#if>
67 },
68 rules: {
69 <#if columns??>
70 <#list columns as column>
71 <#if column.columnName == 'code'>
72 code: [
73 { required: true, message: '请输入标识', trigger: 'blur' }, { validator: this.validateCode, trigger: 'blur' }
74 ],
75 </#if>
76 </#list>
77 </#if>
78 <#function filter columns>
79 <#local result = []>
80 <#list columns as column>
81 <#if column.columnKey != 'PRI' && column.isNullable = 'NO'>
82 <#local result = result + [column]>
83 </#if>
84 </#list>
85 <#return result>
86 </#function>
87 <#assign filteredData = filter(columns)>
88 <#list filteredData as column>
89 ${column.changeColumnName}: [
90 { required: true, message: '${column.columnComment}不能为空', trigger: 'blur' }
91 ]<#sep>,</#sep>
92 </#list>
93 }
94 }
95 },
96 methods: {
97 <#if columns??>
98 <#list columns as column>
99 <#if column.columnName == 'code'>
100 validateCode(rule, value, callback) {
101 // 当为编辑状态且code未改变时不进行校验
102 if (!this.isAdd && this.form.originalCode === value) {
103 callback()
104 } else {
105 getByCode(value)
106 .then(res => {
107 typeof (res) === 'undefined' || res.id === null || this.form.id === res.id
108 ? callback()
109 : callback(new Error('该code已存在!'))
110 })
111 .catch((err) => {
112 console.log(err)
113 callback()
114 })
115 }
116 },
117 </#if>
118 </#list>
119 </#if>
120 cancel() {
121 this.dialog = false
122 },
123 doSubmit() {
124 if (this.isAdd) {
125 this.doAdd()
126 } else this.doEdit()
127 },
128 doAdd() {
129 this.$refs['form'].validate((valid) => {
130 if (valid) {
131 this.loading = true
132 add(this.form).then(() => {
133 this.$notify({
134 title: '添加成功',
135 type: 'success',
136 duration: 2500
137 })
138 this.dialog = false
139 this.loading = false
140 this.$parent.init()
141 }).catch(err => {
142 this.loading = false
143 console.log(err)
144 })
145 } else {
146 this.$notify({
147 title: '警告',
148 message: '信息不合法',
149 type: 'warning',
150 duration: 2000
151 })
152 }
153 })
154 },
155 doEdit() {
156 this.$refs['form'].validate((valid) => {
157 if (valid) {
158 this.loading = true
159 edit(this.form).then(() => {
160 this.$notify({
161 title: '修改成功',
162 type: 'success',
163 duration: 2500
164 })
165 this.loading = false
166 this.dialog = false
167 this.$parent.init()
168 }).catch(err => {
169 console.log(err)
170 this.loading = false
171 })
172 } else {
173 this.$notify({
174 title: '警告',
175 message: '信息不合法',
176 type: 'warning',
177 duration: 2000
178 })
179 }
180 })
181 },
182 doClose() {
183 this.resetForm()
184 },
185 resetForm() {
186 this.$refs['form'].resetFields()
187 this.form = {
188 <#if columns??>
189 <#list columns as column>
190 <#if column.columnName == 'code'>
191 originalCode: '',
192 </#if>
193 ${column.changeColumnName}: ''<#if column_has_next>,</#if>
194 </#list>
195 </#if>
196 }
197 }
198 }
199 }
200 </script>
201
202 <style scoped>
203
204 </style>
1 <#--noinspection ALL-->
2 <template>
3 <div class="app-container">
4 <!--工具栏-->
5 <div class="head-container">
6 <#if hasQuery>
7 <!-- 搜索 -->
8 <el-select v-model="query.type" clearable placeholder="聚合筛选条件" class="filter-item" style="width: 130px">
9 <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
10 </el-select>
11 <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
12 <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
13 </#if>
14 <!-- 新增 -->
15 <div style="display: inline-block;margin: 0 2px;">
16 <el-button
17 v-permission="['admin','${changeClassName}:add']"
18 class="filter-item"
19 size="mini"
20 type="primary"
21 icon="el-icon-plus"
22 @click="add">新增</el-button>
23 </div>
24 </div>
25 <!--表单组件-->
26 <eForm ref="form" :is-add="isAdd" :dict-map="dictMap"/>
27 <!--表格渲染-->
28 <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" @row-dblclick="edit">
29 <#if columns??>
30 <#list columns as column>
31 <#if column.columnShow = 'true'>
32 <#if column.columnType != 'Timestamp'>
33 <el-table-column prop="${column.changeColumnName}" label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.columnName = 'id' || column.columnName = 'name' || column.columnName = 'code'>sortable </#if>/>
34 <#else>
35 <el-table-column prop="${column.changeColumnName}" label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>">
36 <template slot-scope="scope">
37 <span>{{ parseTime(scope.row.${column.changeColumnName}) }}</span>
38 </template>
39 </el-table-column>
40 </#if>
41 </#if>
42 </#list>
43 </#if>
44 <el-table-column label="操作" width="120px" fixed="right" align="center">
45 <template slot-scope="scope">
46 <el-button v-permission="['admin','${changeClassName}:edit']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)"/>
47 <el-popover
48 v-permission="['admin','${changeClassName}:del']"
49 :ref="scope.row.${pkChangeColName}"
50 placement="top"
51 width="180">
52 <p>确定删除本条数据吗?</p>
53 <div style="text-align: right; margin: 0">
54 <el-button size="mini" type="text" @click="$refs[scope.row.${pkChangeColName}].doClose()">取消</el-button>
55 <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.${pkChangeColName})">确定</el-button>
56 </div>
57 <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
58 </el-popover>
59 </template>
60 </el-table-column>
61 </el-table>
62 <!--分页组件-->
63 <el-pagination
64 :total="total"
65 :current-page="page + 1"
66 style="margin-top: 8px;"
67 layout="total, prev, pager, next, sizes"
68 @size-change="sizeChange"
69 @current-change="pageChange"/>
70 </div>
71 </template>
72
73 <script>
74 import initData from '@/mixins/initData'
75 import initDict from '@/mixins/initDict'
76 import { getAttrByValueFromDict } from '@/utils/common-util'
77 import { del, download${className} } from '@/api/${changeClassName}'
78 <#if hasTimestamp>
79 import { parseTime, downloadFile } from '@/utils/index'
80 </#if>
81 import eForm from './form'
82 export default {
83 components: { eForm },
84 mixins: [initData, initDict],
85 data() {
86 return {
87 delLoading: false<#if hasQuery>,</#if>
88 <#if hasQuery>
89 queryTypeOptions: [
90 <#if queryColumns??>
91 <#list queryColumns as column>
92 { key: '${column.changeColumnName}', display_name: '<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>' }<#if column_has_next>,</#if>
93 </#list>
94 </#if>
95 ]
96 </#if>
97 }
98 },
99 created() {
100 this.$nextTick(() => {
101 this.init()
102 this.getDictMap('')
103 })
104 },
105 methods: {
106 <#if hasTimestamp>
107 parseTime,
108 </#if>
109 getAttrByValueFromDict,
110 beforeInit() {
111 this.url = 'api/${changeClassName}'
112 const sort = '${pkChangeColName},desc'
113 this.params = { page: this.page, size: this.size, sort: sort }
114 <#if hasQuery>
115 const query = this.query
116 const type = query.type
117 const value = query.value
118 if (type && value) { this.params[type] = value }
119 </#if>
120 return true
121 },
122 subDelete(${pkChangeColName}) {
123 this.delLoading = true
124 del(${pkChangeColName}).then(res => {
125 this.delLoading = false
126 this.$refs[${pkChangeColName}].doClose()
127 this.dleChangePage()
128 this.init()
129 this.$notify({
130 title: '删除成功',
131 type: 'success',
132 duration: 2500
133 })
134 }).catch(err => {
135 this.delLoading = false
136 this.$refs[${pkChangeColName}].doClose()
137 console.log(err.response.data.message)
138 })
139 },
140 add() {
141 this.isAdd = true
142 this.$refs.form.dialog = true
143 },
144 edit(data) {
145 this.isAdd = false
146 const _this = this.$refs.form
147 _this.form = {
148 <#if columns??>
149 <#list columns as column>
150 <#if column.columnName == 'code'>
151 originalCode: data.code,
152 </#if>
153 ${column.changeColumnName}: data.${column.changeColumnName}<#if column_has_next>,</#if>
154 </#list>
155 </#if>
156 }
157 _this.dialog = true
158 },
159 // 导出
160 download() {
161 this.beforeInit()
162 this.downloadLoading = true
163 download${className}(this.params).then(result => {
164 downloadFile(result, '${className}列表', 'xlsx')
165 this.downloadLoading = false
166 }).catch(() => {
167 this.downloadLoading = false
168 })
169 }
170 }
171 }
172 </script>
173
174 <style scoped>
175
176 </style>
1 package com.topdraw;
2
3
4 import org.junit.runner.RunWith;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7 import org.springframework.boot.test.context.SpringBootTest;
8 import org.springframework.test.context.junit4.SpringRunner;
9
10 @SpringBootTest(classes= MemberServiceApplication.class)
11 @RunWith(SpringRunner.class)
12 public class BaseTest {
13
14 public Logger LOG = LoggerFactory.getLogger(BaseTest.class);
15
16 }
1 package com.topdraw.code;
2
3 import com.topdraw.BaseTest;
4 import com.topdraw.domain.GenConfig;
5 import com.topdraw.domain.vo.ColumnInfo;
6 import com.topdraw.MemberServiceApplication;
7 import com.topdraw.service.GeneratorService;
8 import lombok.var;
9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.boot.test.context.SpringBootTest;
13 import org.springframework.test.annotation.Rollback;
14 import org.springframework.test.context.junit4.SpringRunner;
15 import org.springframework.transaction.annotation.Transactional;
16
17 import java.util.Arrays;
18 import java.util.List;
19 import java.util.Map;
20
21 /**
22 * @author Hongyan Wang
23 * @packageName PACKAGE_NAME
24 * @className GeneratorCode
25 * @description
26 * @date 2020/12/30 0:11
27 */
28 public class GeneratorCode extends BaseTest {
29
30 @Autowired
31 private GeneratorService generatorService;
32
33
34 // @Autowired
35 // private WeixinInfoConfig weixinInfoConfig;
36
37
38 @Test
39 @Rollback(value = false)
40 @Transactional(rollbackFor = Exception.class)
41 public void generator() {
42 var dbName = "uc_tr_task_progress";
43 // 表名称,支持多表
44 var tableNames = Arrays.asList(dbName);
45 String[] s = dbName.split("_");
46
47 var pre = s[0];
48 var target1 = s[s.length-1];
49 var preRoute = "com.topdraw.business.basicdata.task.";
50 StringBuilder builder = new StringBuilder(preRoute);
51 builder.append("progress");
52 // builder.append(target);
53
54 tableNames.forEach(tableName -> {
55 // 生成的表名称
56 // var tableName = "x_media";
57 // 拿参数
58 var columnsMap = (Map<String, Object>) generatorService.getColumns(tableName);
59 var columnInfos = (List<ColumnInfo>) columnsMap.get("content");
60 // 只生成后端的话,只需要配置下包名和是否覆盖,
61 var genConfig = new GenConfig()
62 // 未设置id无法生成
63 .setId(1L)
64 // 根据需求更改包路径
65 .setPack(builder.toString())
66 // 前端路径。不生成前端可置空
67 .setPath("")
68 // 作者
69 .setAuthor("XiangHan")
70 // 表前缀。生成实体时,会移除该前缀
71 .setPrefix(pre)
72 // 若文件存在,是否进行覆盖
73 .setCover(true);
74
75 // 生成代码
76 generatorService.generator(columnInfos, genConfig, tableName);
77 });
78 }
79 }
1 package com.topdraw.test.business.basicdata.member;
2
3 import com.topdraw.business.basicdata.member.service.MemberService;
4 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
5 import com.topdraw.BaseTest;
6 import org.junit.Test;
7 import org.springframework.beans.factory.annotation.Autowired;
8
9 public class MemberServiceTest extends BaseTest {
10
11 @Autowired
12 private MemberService memberService;
13
14 @Test
15 public void findById(){
16 Long memberId = 1L;
17 MemberDTO memberDTO = this.memberService.findById(memberId);
18 LOG.info("=====>>>" + memberDTO);
19
20 }
21
22 }
1 package com.topdraw.test.business.basicdata.member.profile;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.BaseTest;
5 import com.topdraw.business.basicdata.member.profile.domain.MemberProfile;
6 import com.topdraw.business.basicdata.member.profile.service.MemberProfileService;
7 import com.topdraw.business.basicdata.member.service.MemberService;
8 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
9 import com.topdraw.util.TimestampUtil;
10 import org.junit.Test;
11 import org.springframework.beans.factory.annotation.Autowired;
12
13 public class MemberProfileServiceTest extends BaseTest {
14
15 @Autowired
16 private MemberProfileService memberProfileService;
17
18 @Test
19 public void create(){
20 Long memberId = 1L;
21 MemberProfile resources = new MemberProfile();
22 resources.setMemberId(memberId);
23 resources.setIdCard("422827199208010713");
24 resources.setBirthday(TimestampUtil.now());
25 resources.setGender(1);
26 resources.setDescription("");
27 resources.setRealname("");
28 resources.setConstellation("");
29 resources.setProvince("");
30 resources.setCity("");
31 resources.setEmail("");
32 resources.setDistrict("");
33 String s = JSON.toJSONString(resources);
34 this.memberProfileService.create(resources);
35 LOG.info("=====>>>"+s);
36 }
37
38 @Test
39 public void update(){
40 Long memberId = 1L;
41 MemberProfile resources = new MemberProfile();
42 resources.setId(1L);
43 resources.setMemberId(memberId);
44 resources.setCity("sh");
45 String s = JSON.toJSONString(resources);
46 this.memberProfileService.update(resources);
47 LOG.info("=====>>>s=====>>>" + s);
48 }
49
50 @Test
51 public void delete(){
52 Long memberId = 1L;
53 this.memberProfileService.delete(memberId);
54 LOG.info("=====>>>s=====>>>");
55 }
56
57 }
1 package com.topdraw.test.business.basicdata.member.rest;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.business.basicdata.member.address.domain.MemberAddress;
5 import com.topdraw.business.basicdata.member.address.rest.MemberAddressController;
6 import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria;
7 import com.topdraw.common.ResultInfo;
8 import com.topdraw.BaseTest;
9 import org.junit.Test;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.data.domain.PageRequest;
12 import org.springframework.data.domain.Pageable;
13
14 public class MemberAddressControllerTest extends BaseTest {
15
16
17 @Autowired
18 MemberAddressController memberAddressController;
19
20 @Test
21 public void pageMemberAddress(){
22 MemberAddressQueryCriteria memberQueryCriteria = new MemberAddressQueryCriteria();
23 memberQueryCriteria.setMemberId(1L);
24 Pageable pageable = PageRequest.of(0,20);
25 ResultInfo byId = this.memberAddressController.pageMemberAddress(memberQueryCriteria,pageable);
26 LOG.info("===>>>"+byId);
27 }
28
29 @Test
30 public void update(){
31 MemberAddress memberAddress = new MemberAddress();
32 memberAddress.setId(1L);
33 memberAddress.setMemberId(1L);
34 memberAddress.setType(1);
35 memberAddress.setIsDefault(1);
36 memberAddress.setSequence(1);
37 memberAddress.setStatus(1);
38 memberAddress.setContactor("");
39 memberAddress.setCellphone("1");
40 memberAddress.setCountry("");
41 memberAddress.setProvince("final String province");
42 memberAddress.setCity("");
43 memberAddress.setDistrict("");
44 memberAddress.setAddress("");
45 memberAddress.setZipCode("");
46 String s = JSON.toJSONString(memberAddress);
47 ResultInfo byId = this.memberAddressController.update(memberAddress);
48 LOG.info("===>>>"+byId);
49 }
50
51 @Test
52 public void create(){
53 MemberAddress memberAddress = new MemberAddress();
54 // memberAddress.setId(1L);
55 memberAddress.setMemberId(1L);
56 memberAddress.setType(1);
57 memberAddress.setIsDefault(1);
58 memberAddress.setSequence(1);
59 memberAddress.setStatus(1);
60 memberAddress.setContactor("");
61 memberAddress.setCellphone("1");
62 memberAddress.setCountry("");
63 memberAddress.setProvince("final String province");
64 memberAddress.setCity("");
65 memberAddress.setDistrict("");
66 memberAddress.setAddress("");
67 memberAddress.setZipCode("");
68 String s = JSON.toJSONString(memberAddress);
69 ResultInfo byId = this.memberAddressController.create(memberAddress);
70 LOG.info("===>>>"+byId);
71 }
72
73 @Test
74 public void findById(){
75 ResultInfo byId = this.memberAddressController.findById(1L);
76 LOG.info("===>>>"+byId);
77 }
78
79 @Test
80 public void delete(){
81 ResultInfo byId = this.memberAddressController.delete(1L);
82 LOG.info("===>>>"+byId);
83 }
84
85 }
1 package com.topdraw.test.business.basicdata.member.rest;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.business.basicdata.member.domain.Member;
5 import com.topdraw.business.basicdata.member.rest.MemberController;
6 import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria;
7 import com.topdraw.common.ResultInfo;
8 import com.topdraw.BaseTest;
9 import com.topdraw.util.IdWorker;
10 import com.topdraw.util.TimestampUtil;
11 import org.junit.Test;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.data.domain.PageRequest;
14 import org.springframework.data.domain.Pageable;
15
16 public class MemberControllerTest extends BaseTest {
17
18
19 @Autowired
20 MemberController memberController;
21
22 @Test
23 public void update(){
24 Member member = new Member();
25 member.setId(5L);
26 member.setType(1);
27 member.setStatus(1);
28 member.setNickname("五号员工");
29 member.setDescription("description");
30 member.setGender(1);
31 member.setBirthday("birthday");
32 member.setAvatarUrl("avatarUrl");
33 member.setGroups("groups");
34 member.setTags("tags");
35 member.setVip(1);
36 member.setLevel(1);
37 member.setExp(10L);
38 member.setPoints(5L);
39 member.setDuePoints(0L);
40 member.setCouponAmount(1L);
41 member.setDueCouponAmount(0L);
42 member.setUserIptvId(1L);
43 member.setBindIptvPlatformType(0);
44 String s = JSON.toJSONString(member);
45 ResultInfo byId = this.memberController.update(member);
46 LOG.info("===>>>"+byId);
47 }
48
49 @Test
50 public void create(){
51 Member member = new Member();
52 member.setCode(String.valueOf(IdWorker.generator()));
53 member.setType(1);
54 member.setStatus(1);
55 member.setNickname("nickname");
56 member.setDescription("description");
57 member.setGender(1);
58 member.setBirthday("birthday");
59 member.setAvatarUrl("avatarUrl");
60 member.setGroups("groups");
61 member.setTags("tags");
62 member.setVip(1);
63 member.setLevel(1);
64 member.setExp(10L);
65 member.setPoints(5L);
66 member.setDuePoints(0L);
67 member.setCouponAmount(1L);
68 member.setDueCouponAmount(0L);
69 member.setUserIptvId(1L);
70 member.setBindIptvPlatformType(0);
71 member.setUpdateTime(TimestampUtil.now());
72 String s = JSON.toJSONString(member);
73 ResultInfo byId = this.memberController.create(member);
74 LOG.info("===>>>"+byId);
75 }
76
77 }
1 package com.topdraw.test.business.basicdata.member.rest;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo;
5 import com.topdraw.business.basicdata.member.relatedinfo.rest.MemberRelatedInfoController;
6 import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria;
7 import com.topdraw.common.ResultInfo;
8 import com.topdraw.BaseTest;
9 import org.junit.Test;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.data.domain.PageRequest;
12 import org.springframework.data.domain.Pageable;
13
14 //public class MemberControllerTest {
15 public class MemberRelatedInfoControllerTest extends BaseTest {
16
17
18 @Autowired
19 MemberRelatedInfoController memberRelatedInfoController;
20
21 @Test
22 public void getMembers(){
23 MemberRelatedInfoQueryCriteria memberQueryCriteria = new MemberRelatedInfoQueryCriteria();
24 Pageable pageable = PageRequest.of(0,20);
25 ResultInfo byId = this.memberRelatedInfoController.pageMemberRelatedInfos(memberQueryCriteria,pageable);
26 LOG.info("===>>>"+byId);
27 }
28
29 @Test
30 public void update(){
31 MemberRelatedInfo member = new MemberRelatedInfo();
32 member.setId(1L);
33 // member.setMemberId(2L);
34 member.setType(1);
35 member.setCellphone("18271269120");
36 member.setIdCard("422827199208010713");
37 member.setName("fdfd");
38 member.setSex(1);
39 // member.setCreateTime();
40 // member.setUpdateTime();
41 String s = JSON.toJSONString(member);
42 ResultInfo byId = this.memberRelatedInfoController.update(member);
43 LOG.info("===>>>"+byId);
44 }
45
46 @Test
47 public void create(){
48 MemberRelatedInfo member = new MemberRelatedInfo();
49 // member.setId(final Long id);
50 member.setMemberId(2L);
51 member.setType(1);
52 member.setCellphone("18271269120");
53 member.setIdCard("422827199208010713");
54 member.setName("fdfd");
55 member.setSex(1);
56 // member.setCreateTime();
57 // member.setUpdateTime();
58 String s = JSON.toJSONString(member);
59 ResultInfo byId = this.memberRelatedInfoController.create(member);
60 LOG.info("===>>>"+byId);
61 }
62
63 @Test
64 public void findById(){
65 ResultInfo byId = this.memberRelatedInfoController.findById(1L);
66 LOG.info("===>>>"+byId);
67 }
68
69 @Test
70 public void delete(){
71 ResultInfo byId = this.memberRelatedInfoController.delete(1L);
72 LOG.info("===>>>"+byId);
73 }
74
75 }
1 package com.topdraw.test.business.basicdata.points;
2
3 import com.topdraw.business.basicdata.points.available.domain.PointsAvailable;
4 import com.topdraw.business.basicdata.points.available.service.PointsAvailableService;
5 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO;
6 import com.topdraw.business.process.domian.TempPoints;
7 import com.topdraw.BaseTest;
8 import com.topdraw.util.DateUtil;
9 import com.topdraw.util.IdWorker;
10 import com.topdraw.util.TimestampUtil;
11 import org.junit.Test;
12 import org.springframework.beans.BeanUtils;
13 import org.springframework.beans.factory.annotation.Autowired;
14
15 import java.util.List;
16
17 public class PointsAvailableServiceTest extends BaseTest {
18
19 @Autowired
20 private PointsAvailableService pointsAvailableService;
21
22 @Test
23 public void loadListExpirePointsByMemberId() {
24 Long memberId = 2L;
25 List<PointsAvailableDTO> pointsAvailableDTOS =
26 this.pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId, DateUtil.newDate());
27 LOG.info("===>>>"+pointsAvailableDTOS);
28 }
29
30
31 @Test
32 public void findSoonExpireTime(){
33 Long memberId = 2L;
34 Long soonExpireTime = this.pointsAvailableService.findSoonExpireTime(memberId, 30);
35 LOG.info("=====>>>"+soonExpireTime);
36
37 }
38
39 @Test
40 public void create(){
41 Long memberId = 2L;
42 TempPoints tempPoints = new TempPoints();
43 tempPoints.setMemberId(memberId);
44 tempPoints.setPointsType(0);
45 tempPoints.setRightsSendStrategy(1);
46 tempPoints.setActivityId(0L);
47 tempPoints.setOrderId(0L);
48 tempPoints.setDeviceType(2);
49 tempPoints.setMediaId(0L);
50 tempPoints.setAccountId(1L);
51 tempPoints.setAppCode("OMO");
52 // tempPoints.setDescription("#");
53 tempPoints.setEvtType(1);
54 tempPoints.setPoints(10L);
55 tempPoints.setExpireTime(TimestampUtil.now());
56
57 PointsAvailable pointsAvailable = new PointsAvailable();
58 BeanUtils.copyProperties(tempPoints,pointsAvailable);
59
60 pointsAvailable.setMemberId(memberId);
61 pointsAvailable.setCode(String.valueOf(IdWorker.generator()));
62 this.pointsAvailableService.create(pointsAvailable);
63 LOG.info("=====>>>");
64
65 }
66
67 }
1 package com.topdraw.test.business.basicdata.points;
2
3 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
4 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
5 import com.topdraw.business.basicdata.points.detail.service.PointsDetailService;
6 import com.topdraw.business.process.service.MemberOperationService;
7 import com.topdraw.business.process.domian.TempPoints;
8 import com.topdraw.BaseTest;
9 import com.topdraw.util.IdWorker;
10 import com.topdraw.util.TimestampUtil;
11 import org.junit.Test;
12 import org.springframework.beans.BeanUtils;
13 import org.springframework.beans.factory.annotation.Autowired;
14
15 public class PointsDetailServiceTest extends BaseTest {
16
17 @Autowired
18 private PointsDetailService pointsDetailService;
19 @Autowired
20 MemberOperationService memberOperationService;
21
22 @Test
23 public void create(){
24 Long memberId = 2L;
25
26 TempPoints tempPoints = new TempPoints();
27 tempPoints.setMemberId(memberId);
28 tempPoints.setPointsType(0);
29 tempPoints.setRightsSendStrategy(1);
30 tempPoints.setActivityId(0L);
31 tempPoints.setOrderId(0L);
32 tempPoints.setDeviceType(2);
33 tempPoints.setMediaId(0L);
34 tempPoints.setAccountId(1L);
35 tempPoints.setAppCode("OMO");
36 tempPoints.setDescription("");
37 tempPoints.setEvtType(1);
38 tempPoints.setPoints(10L);
39 tempPoints.setExpireTime(TimestampUtil.now());
40
41 MemberDTO memberDTO = this.memberOperationService.findById(memberId);
42
43 PointsDetail pointsDetail = new PointsDetail();
44 BeanUtils.copyProperties(tempPoints,pointsDetail);
45
46 // 获取的积分
47 long rewardPoints = tempPoints.getPoints();
48 // 原始积分
49 long originalPoints = memberDTO.getPoints();
50
51 pointsDetail.setMemberId(memberId);
52 pointsDetail.setCode(String.valueOf(IdWorker.generator()));
53
54 pointsDetail.setOriginalPoints(originalPoints);
55 pointsDetail.setResultPoints(originalPoints+rewardPoints);
56 this.pointsDetailService.create(pointsDetail);
57 LOG.info("=====>>>");
58
59 }
60
61 }
1 package com.topdraw.test.business.basicdata.rights;
2
3 import com.topdraw.BaseTest;
4 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
5 import com.topdraw.business.basicdata.points.detail.domain.PointsDetail;
6 import com.topdraw.business.basicdata.points.detail.service.PointsDetailService;
7 import com.topdraw.business.process.domian.TempPoints;
8 import com.topdraw.business.process.service.MemberOperationService;
9 import com.topdraw.util.IdWorker;
10 import com.topdraw.util.TimestampUtil;
11 import org.junit.Test;
12 import org.springframework.beans.BeanUtils;
13 import org.springframework.beans.factory.annotation.Autowired;
14
15 public class RightsServiceTest extends BaseTest {
16
17 @Autowired
18 private PointsDetailService pointsDetailService;
19 @Autowired
20 MemberOperationService memberOperationService;
21
22 @Test
23 public void create(){
24 Long memberId = 2L;
25
26 TempPoints tempPoints = new TempPoints();
27 tempPoints.setMemberId(memberId);
28 tempPoints.setPointsType(0);
29 tempPoints.setRightsSendStrategy(1);
30 tempPoints.setActivityId(0L);
31 tempPoints.setOrderId(0L);
32 tempPoints.setDeviceType(2);
33 tempPoints.setMediaId(0L);
34 tempPoints.setAccountId(1L);
35 tempPoints.setAppCode("OMO");
36 tempPoints.setDescription("");
37 tempPoints.setEvtType(1);
38 tempPoints.setPoints(10L);
39 tempPoints.setExpireTime(TimestampUtil.now());
40
41 MemberDTO memberDTO = this.memberOperationService.findById(memberId);
42
43 PointsDetail pointsDetail = new PointsDetail();
44 BeanUtils.copyProperties(tempPoints,pointsDetail);
45
46 // 获取的积分
47 long rewardPoints = tempPoints.getPoints();
48 // 原始积分
49 long originalPoints = memberDTO.getPoints();
50
51 pointsDetail.setMemberId(memberId);
52 pointsDetail.setCode(String.valueOf(IdWorker.generator()));
53
54 pointsDetail.setOriginalPoints(originalPoints);
55 pointsDetail.setResultPoints(originalPoints+rewardPoints);
56 this.pointsDetailService.create(pointsDetail);
57 LOG.info("=====>>>");
58
59 }
60
61 }
1 package com.topdraw.test.business.basicdata.rights.history;
2
3 import com.topdraw.BaseTest;
4 import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria;
5 import com.topdraw.business.basicdata.rights.history.rest.RightsHistoryController;
6 import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria;
7 import com.topdraw.business.basicdata.rights.rest.RightsController;
8 import com.topdraw.common.ResultInfo;
9 import org.junit.Test;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.data.domain.PageRequest;
12 import org.springframework.data.domain.Pageable;
13
14 public class RightsHistoryControllerTest extends BaseTest {
15
16
17 @Autowired
18 RightsHistoryController rightsHistoryController;
19
20 @Test
21 public void pageRightsHistory(){
22 RightsHistoryQueryCriteria memberQueryCriteria = new RightsHistoryQueryCriteria();
23 memberQueryCriteria.setMemberId(1L);
24 Pageable pageable = PageRequest.of(0,20);
25 ResultInfo byId = this.rightsHistoryController.pageRightsHistory(memberQueryCriteria,pageable);
26 LOG.info("===>>>"+byId);
27 }
28
29
30 @Test
31 public void pageAvailableRights(){
32 RightsHistoryQueryCriteria memberQueryCriteria = new RightsHistoryQueryCriteria();
33 memberQueryCriteria.setMemberId(1L);
34 Pageable pageable = PageRequest.of(0,20);
35 ResultInfo byId = this.rightsHistoryController.pageAvailableRights(memberQueryCriteria,pageable);
36 LOG.info("===>>>"+byId);
37 }
38
39 }
1 package com.topdraw.test.business.basicdata.rights.permanentrights;
2
3 import com.topdraw.BaseTest;
4 import com.topdraw.business.basicdata.rights.permanentrights.rest.PermanentRightsController;
5 import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsQueryCriteria;
6 import com.topdraw.business.basicdata.rights.rest.RightsController;
7 import com.topdraw.common.ResultInfo;
8 import org.junit.Test;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.data.domain.PageRequest;
11 import org.springframework.data.domain.Pageable;
12
13 public class PermanentRightsControllerTest extends BaseTest {
14
15
16 @Autowired
17 PermanentRightsController permanentRightsController;
18
19 @Test
20 public void pagePermanentRights(){
21 PermanentRightsQueryCriteria criteria = new PermanentRightsQueryCriteria();
22 criteria.setLevel(2);
23 Pageable pageable = PageRequest.of(0,20);
24 ResultInfo byId = this.permanentRightsController.pagePermanentRights(criteria,pageable);
25 LOG.info("===>>>"+byId);
26 }
27
28 @Test
29 public void findById(){
30 ResultInfo byId = this.permanentRightsController.findById(1L);
31 LOG.info("===>>>"+byId);
32 }
33
34 /*@Test
35 public void create(){
36 ResultInfo byId = this.permanentRightsController.create(1L);
37 LOG.info("===>>>"+byId);
38 }
39
40 @Test
41 public void update(){
42 ResultInfo byId = this.permanentRightsController.update(1L);
43 LOG.info("===>>>"+byId);
44 }
45
46 @Test
47 public void delete(){
48 ResultInfo byId = this.permanentRightsController.delete(1L);
49 LOG.info("===>>>"+byId);
50 }*/
51
52 }
1 package com.topdraw.test.business.basicdata.rights.rest;
2
3 import com.topdraw.BaseTest;
4 import com.topdraw.business.basicdata.rights.rest.RightsController;
5 import com.topdraw.common.ResultInfo;
6 import org.junit.Test;
7 import org.springframework.beans.factory.annotation.Autowired;
8
9 public class RightsControllerTest extends BaseTest {
10
11
12 @Autowired
13 RightsController rightsController;
14
15 @Test
16 public void findById(){
17 ResultInfo byId = this.rightsController.findById(1L);
18 LOG.info("===>>>"+byId);
19 }
20
21 }
1 package com.topdraw.test.business.basicdata.task;
2
3 import com.topdraw.business.basicdata.member.domain.Member;
4 import com.topdraw.business.basicdata.member.service.dto.MemberDTO;
5 import com.topdraw.business.basicdata.task.domain.Task;
6 import com.topdraw.business.basicdata.task.service.TaskService;
7 import com.topdraw.BaseTest;
8 import com.topdraw.business.process.service.impl.CompareTaskCondition;
9 import com.topdraw.util.IdWorker;
10 import com.topdraw.util.TimestampUtil;
11 import org.assertj.core.util.Arrays;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.util.CollectionUtils;
16
17 import java.sql.Timestamp;
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Objects;
21 import java.util.stream.Collectors;
22
23 //public class TaskServiceTest extends BaseTest {
24 public class TaskServiceTest {
25
26 @Test
27 public void dealTaskTest(){
28 // List<Task> taskList = this.taskService.findByTemplateId(1L);
29 // LOG.info("=====>>>" + taskList);
30 Task task = new Task();
31 task.setTaskTemplateId(1L);
32 task.setTaskDailyReset(1);
33 task.setActionAmount(1);
34 task.setValidTime(TimestampUtil.now());
35 task.setExpireTime(TimestampUtil.now());
36 task.setSequence(1);
37 task.setRewardExp(10L);
38 task.setRewardPoints(1L);
39 task.setRewardPointsExpireTime(TimestampUtil.Timestamp2long(TimestampUtil.now()));
40 task.setPointsType(1);
41 task.setRewardMaxPoints(1);
42 task.setGroups("groups");
43 task.setRightsSendStrategy(1);
44 task.setMemberLevel(1);
45 task.setMemberVip(1);
46 task.setRightsId(1L);
47 task.setRightsAmount(1);
48 task.setRights2Id(2L);
49 task.setRights2Amount(1);
50 task.setRights3Id(3L);
51 task.setRights3Amount(1);
52 task.setStatus(1);
53 List<Task> taskList = new ArrayList<>();
54 taskList.add(task);
55
56 MemberDTO member = new MemberDTO();
57 member.setCode(String.valueOf(IdWorker.generator()));
58 member.setType(1);
59 member.setStatus(1);
60 member.setNickname("nickname");
61 member.setDescription("description");
62 member.setGender(1);
63 member.setBirthday("birthday");
64 member.setAvatarUrl("avatarUrl");
65 member.setGroups("groups");
66 member.setTags("tags");
67 member.setVip(1);
68 member.setLevel(1);
69 member.setExp(10L);
70 member.setPoints(5L);
71 member.setDuePoints(0L);
72 member.setCouponAmount(1L);
73 member.setDueCouponAmount(0L);
74 member.setUserIptvId(1L);
75 member.setBindIptvPlatformType(0);
76 member.setUpdateTime(TimestampUtil.now());
77
78 // 判断是否完成任务
79 CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1, List<Task> taskList1) -> {
80
81 List<Task> taskStream = taskList1.stream().filter(task1 ->
82 task1.getStatus() == 1 &&
83 (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) <= 0) &&
84 (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) &&
85 (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) &&
86 (task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) &&
87 (task1.getMemberVip() == 0 || task1.getMemberVip() == memberDTO1.getVip())
88 ).collect(Collectors.toList());
89
90 if (CollectionUtils.isEmpty(taskStream)) {
91 return false;
92 }
93 return true;
94 };
95 boolean b = compareTaskCondition.compareCondition(member, taskList);
96 System.out.println(b);
97 }
98 }
1 package com.topdraw.test.business.basicdata.task;
2
3 import com.topdraw.business.basicdata.task.template.domain.TaskTemplate;
4 import com.topdraw.business.basicdata.task.template.service.TaskTemplateService;
5 import com.topdraw.BaseTest;
6 import org.junit.Test;
7 import org.springframework.beans.factory.annotation.Autowired;
8
9 public class TaskTemplateServiceTest extends BaseTest {
10
11 @Autowired
12 TaskTemplateService taskTemplateService;
13
14 @Test
15 public void dealTaskTest(){
16 String eventCode = "tv";
17 TaskTemplate taskTemplate = this.taskTemplateService.findByEvent(eventCode);
18 LOG.info("=====>>>" + taskTemplate);
19
20 }
21
22 }
1 package com.topdraw.test.business.process.rest;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.BaseTest;
5 import com.topdraw.business.process.domian.TempCoupon;
6 import com.topdraw.business.process.rest.CouponOperationController;
7 import com.topdraw.common.ResultInfo;
8 import org.junit.Test;
9 import org.springframework.beans.factory.annotation.Autowired;
10
11 import java.sql.Timestamp;
12 import java.util.ArrayList;
13 import java.util.List;
14
15 public class CouponOperationControllerTest extends BaseTest {
16
17 @Autowired
18 CouponOperationController couponOperationController;
19
20 @Test
21 public void grantCouponByManual(){
22 Long memberId = 2L;
23 Long userId = 2L;
24 TempCoupon tempCoupon = new TempCoupon();
25 tempCoupon.setId(1L);
26 tempCoupon.setRightsAmount(1);
27 tempCoupon.setCode("233");
28 tempCoupon.setUseStatus(1);
29 tempCoupon.setUserNickname("");
30 tempCoupon.setMemberId(2L);
31 tempCoupon.setRightsSendStrategy(0);
32 tempCoupon.setAccountId(2L);
33 tempCoupon.setExpireTime(Timestamp.valueOf("2021-10-28 09:00:00"));
34 tempCoupon.setDeviceType(2);
35 tempCoupon.setAppCode("WEI_XIN_GOLD_PANDA");
36 tempCoupon.setOrderId(null);
37 tempCoupon.setMediaId(null);
38 tempCoupon.setActivityId(null);
39 tempCoupon.setItemId(null);
40 tempCoupon.setDescription("#");
41 tempCoupon.setEvtType(1);
42
43 List<TempCoupon> tempCouponList = new ArrayList<>();
44 tempCouponList.add(tempCoupon);
45
46 String s = JSON.toJSONString(tempCouponList);
47 // tempCouponList.add(tempCoupon1);
48 ResultInfo byId = this.couponOperationController.grantCouponByManual(memberId,userId,tempCouponList);
49 LOG.info("===>>>"+byId);
50 }
51
52
53
54 }
1 package com.topdraw.test.business.process.rest;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.BaseTest;
5 import com.topdraw.business.process.domian.TempCoupon;
6 import com.topdraw.business.process.domian.TempExp;
7 import com.topdraw.business.process.rest.CouponOperationController;
8 import com.topdraw.business.process.rest.ExpOperationController;
9 import com.topdraw.common.ResultInfo;
10 import org.junit.Test;
11 import org.springframework.beans.factory.annotation.Autowired;
12
13 import java.sql.Timestamp;
14 import java.util.ArrayList;
15 import java.util.List;
16
17 public class ExpOperationControllerTest extends BaseTest {
18
19 @Autowired
20 ExpOperationController expOperationController;
21
22 @Test
23 public void grantExpByManual(){
24 Long memberId = 2L;
25 Long userId = 2L;
26 TempExp tempExp = new TempExp();
27 tempExp.setMemberId(memberId);
28 tempExp.setRewardExp(10L);
29 tempExp.setMemberId(2L);
30 tempExp.setRightsSendStrategy(0);
31 tempExp.setAccountId(userId);
32 tempExp.setExpireTime(Timestamp.valueOf("2021-10-28 09:00:00"));
33 tempExp.setDeviceType(2);
34 tempExp.setAppCode("WEI_XIN_GOLD_PANDA");
35 tempExp.setOrderId(null);
36 tempExp.setMediaId(null);
37 tempExp.setActivityId(null);
38 tempExp.setItemId(null);
39 tempExp.setDescription("#");
40 tempExp.setEvtType(1);
41
42 String s = JSON.toJSONString(tempExp);
43 // tempCouponList.add(tempCoupon1);
44 ResultInfo byId = this.expOperationController.grantExpByManual(tempExp);
45 LOG.info("===>>>"+byId);
46 }
47
48
49
50 }
1 package com.topdraw.test.business.process.rest;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria;
5 import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryType;
6 import com.topdraw.business.basicdata.points.detail.rest.PointsDetailController;
7 import com.topdraw.BaseTest;
8 import com.topdraw.business.basicdata.points.detail.service.dto.PointsDetailQueryCriteria;
9 import com.topdraw.business.process.domian.TempPoints;
10 import com.topdraw.business.process.rest.PointsOperationController;
11 import com.topdraw.common.ResultInfo;
12 import org.junit.Test;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.data.domain.PageRequest;
15 import org.springframework.data.domain.Pageable;
16
17 import java.sql.Timestamp;
18
19 public class PointsOperationControllerTest extends BaseTest {
20
21
22 @Autowired
23 PointsOperationController pointsOperationController;
24
25 @Test
26 public void customPoints() {
27 Long memberId = 2L;
28 /*DataSyncMsg dataSyncMsg = new DataSyncMsg();
29 dataSyncMsg.setEntityType(EntityType.MEMBER);
30 dataSyncMsg.setEventType(EventType.VIEWING);
31 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
32 msgData.setEvent(1);
33 msgData.setRemarks("remark");
34 msgData.setMemberId(memberId);
35 msgData.setDeviceType(2);
36
37 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
38 dataSyncMsg.setMsgData(msgData);*/
39
40 TempPoints tempPoints = new TempPoints();
41 tempPoints.setMemberId(memberId);
42 tempPoints.setPoints(1L);
43 tempPoints.setEvtType(1);
44 tempPoints.setAppCode("PADON");
45 tempPoints.setPointsType(0);
46 tempPoints.setMediaId(1L);
47 tempPoints.setDeviceType(1);
48
49 String s = JSON.toJSONString(tempPoints);
50 this.pointsOperationController.customPoints(tempPoints);
51 }
52
53 @Test
54 public void grantPointsByManual(){
55 TempPoints tempPoints = new TempPoints();
56 tempPoints.setPoints(10L);
57 tempPoints.setPointsType(0);
58 tempPoints.setMemberId(2L);
59 tempPoints.setRightsSendStrategy(0);
60 tempPoints.setAccountId(2L);
61 tempPoints.setExpireTime(Timestamp.valueOf("2021-10-27 09:00:00"));
62 tempPoints.setDeviceType(2);
63 tempPoints.setAppCode("WEI_XIN_GOLD_PANDA");
64 tempPoints.setOrderId(null);
65 tempPoints.setMediaId(null);
66 tempPoints.setActivityId(null);
67 tempPoints.setItemId(null);
68 tempPoints.setDescription("#");
69 tempPoints.setEvtType(1);
70 String s = JSON.toJSONString(tempPoints);
71 ResultInfo byId = this.pointsOperationController.grantPointsByManual(tempPoints);
72 LOG.info("===>>>"+byId);
73 }
74
75 /*@Test
76 public void update(){
77 MemberAddress memberAddress = new MemberAddress();
78 memberAddress.setId(1L);
79 memberAddress.setMemberId(1L);
80 memberAddress.setType(1);
81 memberAddress.setIsDefault(1);
82 memberAddress.setSequence(1);
83 memberAddress.setStatus(1);
84 memberAddress.setContactor("");
85 memberAddress.setCellphone("1");
86 memberAddress.setCountry("");
87 memberAddress.setProvince("final String province");
88 memberAddress.setCity("");
89 memberAddress.setDistrict("");
90 memberAddress.setAddress("");
91 memberAddress.setZipCode("");
92 String s = JSON.toJSONString(memberAddress);
93 ResultInfo byId = this.memberAddressController.update(memberAddress);
94 LOG.info("===>>>"+byId);
95 }
96
97 @Test
98 public void create(){
99 PointsDetail memberAddress = new PointsDetail();
100
101 String s = JSON.toJSONString(memberAddress);
102 ResultInfo byId = this.pointsDetailController.create(memberAddress);
103 LOG.info("===>>>"+byId);
104 }
105
106 @Test
107 public void findById(){
108 ResultInfo byId = this.memberAddressController.findById(1L);
109 LOG.info("===>>>"+byId);
110 }
111
112 @Test
113 public void delete(){
114 ResultInfo byId = this.memberAddressController.delete(1L);
115 LOG.info("===>>>"+byId);
116 }*/
117
118 }
1 package com.topdraw.test.business.process.rest;
2
3
4 import com.topdraw.BaseTest;
5 import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
6 import com.topdraw.business.process.rest.RightsOperationController;
7 import com.topdraw.common.ResultInfo;
8 import com.topdraw.util.TimestampUtil;
9 import org.junit.Test;
10 import org.springframework.beans.factory.annotation.Autowired;
11
12 public class RightOperationControllerTest extends BaseTest {
13
14 @Autowired
15 RightsOperationController rightsOperationController;
16
17 @Test
18 public void grantRightsByManual(){
19 RightsHistory rightsHistory = new RightsHistory();
20 rightsHistory.setRightsId(1L);
21 rightsHistory.setMemberId(5L);
22 rightsHistory.setOperatorId(3L);
23 rightsHistory.setOperatorName("鲁二龙");
24 rightsHistory.setExpireTime(TimestampUtil.now());
25 rightsHistory.setUserId(2L);
26 ResultInfo byId = this.rightsOperationController.grantRightsByManual(rightsHistory);
27 LOG.info("===>>>"+byId);
28 }
29
30
31
32 }
1 package com.topdraw.test.business.process.rest;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria;
5 import com.topdraw.business.process.rest.TaskOperationController;
6 import com.topdraw.business.process.rest.TaskOperationQueryCriteria;
7 import com.topdraw.module.mq.DataSyncMsg;
8 import com.topdraw.module.mq.EntityType;
9 import com.topdraw.module.mq.EventType;
10 import com.topdraw.BaseTest;
11 import org.junit.Test;
12 import org.springframework.beans.factory.annotation.Autowired;
13
14 public class TaskOperationControllerTest extends BaseTest {
15
16 @Autowired
17 TaskOperationController taskOperationController;
18
19 @Test
20 public void dealTask() {
21 try {
22 DataSyncMsg dataSyncMsg = new DataSyncMsg();
23 dataSyncMsg.setEventType(EventType.LOGIN.name());
24 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
25 msgData.setEvent(1);
26 msgData.setRemarks("remark");
27 msgData.setMemberId(1L);
28 msgData.setDeviceType(2);
29 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
30 dataSyncMsg.setMsg(msgData);
31 String s = JSON.toJSONString(dataSyncMsg);
32 TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
33 pointsQueryCriteria.setContent(s);
34 this.taskOperationController.dealTask(pointsQueryCriteria);
35 } catch (Exception e) {
36 e.printStackTrace();
37 }
38
39 }
40
41
42
43 }
1 package com.topdraw.test.business.process.service;
2
3 import com.topdraw.business.basicdata.member.domain.Member;
4 import com.topdraw.business.process.service.MemberOperationService;
5 import com.topdraw.BaseTest;
6 import com.topdraw.util.IdWorker;
7 import com.topdraw.util.TimestampUtil;
8 import org.junit.Test;
9 import org.springframework.beans.factory.annotation.Autowired;
10
11 public class MemberOperationServiceTest extends BaseTest {
12
13 @Autowired
14 MemberOperationService memberOperationService;
15
16 @Test
17 public void findById() {
18 Long memberId = 2L;
19 this.memberOperationService.findById(memberId);
20 }
21
22 @Test
23 public void doUpdateMemberInfo() {
24 Member member = new Member();
25 member.setId(2L);
26 member.setCode(String.valueOf(IdWorker.generator()));
27 member.setType(1);
28 member.setStatus(1);
29 member.setNickname("nickname");
30 member.setDescription("description");
31 member.setGender(1);
32 member.setBirthday("birthday");
33 member.setAvatarUrl("avatarUrl");
34 member.setGroups("groups");
35 member.setTags("tags");
36 member.setVip(1);
37 member.setLevel(1);
38 member.setExp(10L);
39 member.setPoints(5L);
40 member.setDuePoints(0L);
41 member.setCouponAmount(1L);
42 member.setDueCouponAmount(0L);
43 member.setUserIptvId(1L);
44 member.setBindIptvPlatformType(0);
45 member.setUpdateTime(TimestampUtil.now());
46 this.memberOperationService.doUpdateMemberInfo(member);
47 }
48
49 @Test
50 public void doInsertMember() {
51 Member member = new Member();
52 member.setCode(String.valueOf(IdWorker.generator()));
53 member.setType(1);
54 member.setStatus(1);
55 member.setNickname("nickname");
56 member.setDescription("description");
57 member.setGender(1);
58 member.setBirthday("birthday");
59 member.setAvatarUrl("avatarUrl");
60 member.setGroups("groups");
61 member.setTags("tags");
62 member.setVip(1);
63 member.setLevel(1);
64 member.setExp(0L);
65 member.setPoints(0L);
66 member.setDuePoints(0L);
67 member.setCouponAmount(0L);
68 member.setDueCouponAmount(0L);
69 member.setUserIptvId(1L);
70 member.setBindIptvPlatformType(0);
71 member.setBindIptvTime(TimestampUtil.now());
72 member.setCreateTime(TimestampUtil.now());
73 member.setUpdateTime(TimestampUtil.now());
74 // member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now()));
75 this.memberOperationService.doInsertMember(member);
76 }
77
78 }
1 package com.topdraw.test.business.process.service;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.BaseTest;
5 import com.topdraw.business.process.domian.TempPoints;
6 import com.topdraw.business.process.service.PointsOperationService;
7 import com.topdraw.business.process.service.TaskOperationService;
8 import com.topdraw.module.mq.DataSyncMsg;
9 import com.topdraw.module.mq.EntityType;
10 import com.topdraw.module.mq.EventType;
11 import org.junit.Test;
12 import org.springframework.beans.factory.annotation.Autowired;
13
14 public class PointsOperationServiceTest extends BaseTest {
15
16 @Autowired
17 PointsOperationService pointsOperationService;
18
19 @Test
20 public void customPoints() {
21 Long memberId = 2L;
22 /*DataSyncMsg dataSyncMsg = new DataSyncMsg();
23 dataSyncMsg.setEntityType(EntityType.MEMBER);
24 dataSyncMsg.setEventType(EventType.VIEWING);
25 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
26 msgData.setEvent(1);
27 msgData.setRemarks("remark");
28 msgData.setMemberId(memberId);
29 msgData.setDeviceType(2);
30
31 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
32 dataSyncMsg.setMsgData(msgData);*/
33
34 TempPoints tempPoints = new TempPoints();
35 tempPoints.setMemberId(memberId);
36 tempPoints.setPoints(1L);
37 tempPoints.setEvtType(1);
38 tempPoints.setAppCode("PADON");
39 tempPoints.setPointsType(0);
40 tempPoints.setMediaId(1L);
41 tempPoints.setDeviceType(1);
42
43 String s = JSON.toJSONString(tempPoints);
44 this.pointsOperationService.customPoints(tempPoints);
45 }
46
47 @Test
48 public void cleanInvalidAvailablePoints() {
49 this.pointsOperationService.cleanInvalidAvailablePoints();
50 }
51
52 }
1 package com.topdraw.test.business.process.service;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.business.process.service.TaskOperationService;
5 import com.topdraw.module.mq.DataSyncMsg;
6 import com.topdraw.module.mq.EntityType;
7 import com.topdraw.module.mq.EventType;
8 import com.topdraw.BaseTest;
9 import org.junit.Test;
10 import org.springframework.beans.factory.annotation.Autowired;
11
12 public class TaskOperationServiceTest extends BaseTest {
13
14 @Autowired
15 TaskOperationService taskOperationService;
16
17 @Test
18 public void dealTaskTest() {
19 Long memberId = 2L;
20 DataSyncMsg dataSyncMsg = new DataSyncMsg();
21 // dataSyncMsg.setEntityType(EntityType.MEMBER);
22 dataSyncMsg.setEventType(EventType.LOGIN.name());
23 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
24 msgData.setEvent(1);
25 msgData.setRemarks("remark");
26 msgData.setMemberId(memberId);
27 msgData.setDeviceType(2);
28
29 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
30 dataSyncMsg.setMsg(msgData);
31
32 String s = JSON.toJSONString(dataSyncMsg);
33 this.taskOperationService.dealTask(s);
34 }
35
36 }
1 package com.topdraw.test.mq;
2
3 import com.alibaba.fastjson.JSON;
4 import com.topdraw.BaseTest;
5 import com.topdraw.module.mq.DataSyncMsg;
6 import com.topdraw.module.mq.EventType;
7 import com.topdraw.mq.config.RabbitMqConfig;
8 import com.topdraw.mq.producer.MessageProducer;
9 import org.junit.Test;
10 import org.springframework.amqp.core.AmqpTemplate;
11 import org.springframework.beans.factory.annotation.Autowired;
12
13 public class MqTest extends BaseTest {
14
15 @Autowired
16 MessageProducer messageProducer;
17
18 @Autowired
19 private AmqpTemplate amqpTemplate;
20
21 @Test
22 public void test(){
23 DataSyncMsg dataSyncMsg = new DataSyncMsg();
24 dataSyncMsg.setEventType(EventType.LOGIN.name());
25 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
26 msgData.setEvent(1);
27 msgData.setRemarks("remark");
28 msgData.setMemberId(1L);
29 msgData.setDeviceType(2);
30 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
31 dataSyncMsg.setMsg(msgData);
32 String s = JSON.toJSONString(dataSyncMsg);
33 amqpTemplate.convertAndSend( "uc.route.key.direct.event.aaa", s);
34 }
35
36 }
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <modelVersion>4.0.0</modelVersion>
6 <packaging>pom</packaging>
7 <modules>
8 <module>member-service-api</module>
9 <module>member-service-impl</module>
10 </modules>
11
12 <parent>
13 <groupId>org.springframework.boot</groupId>
14 <artifactId>spring-boot-starter-parent</artifactId>
15 <version>2.2.10.RELEASE</version>
16 <relativePath/>
17 </parent>
18
19 <groupId>com.topdraw</groupId>
20 <artifactId>member-service</artifactId>
21 <version>0.0.1-SNAPSHOT</version>
22
23 </project>
...\ No newline at end of file ...\ No newline at end of file