PointsOperationController.java
7.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.topdraw.business.process.rest;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.points.available.service.PointsAvailableService;
import com.topdraw.business.module.points.available.service.dto.PointsAvailableQueryCriteria;
import com.topdraw.business.module.points.available.service.dto.PointsAvailableQueryType;
import com.topdraw.business.module.points.detail.service.PointsDetailService;
import com.topdraw.business.module.points.detail.service.dto.PointsDetailQueryCriteria;
import com.topdraw.business.module.user.iptv.service.UserTvService;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.weixin.service.UserWeixinService;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.process.domian.TempCustomPointBean;
import com.topdraw.business.process.domian.TempPoints;
import com.topdraw.business.process.domian.result.CustomPointsResult;
import com.topdraw.business.process.service.PointsOperationService;
import com.topdraw.common.ResultInfo;
import com.topdraw.config.LocalConstants;
import com.topdraw.util.TimestampUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Objects;
/**
* @author XiangHan
* @date 2021-10-22
*/
@Api(tags = "PointsOperation管理")
@RestController
@RequestMapping("/ucEngine/api/pointsOperation")
public class PointsOperationController {
private static final Logger LOG = LoggerFactory.getLogger(PointsOperationController.class);
@Autowired
PointsOperationService pointsOperationService;
@Autowired
PointsDetailService pointsDetailService;
@Autowired
PointsAvailableService pointsAvailableService;
@Autowired
UserTvService userTvService;
@Autowired
UserWeixinService userWeixinService;
@Autowired
MemberService memberService;
@GetMapping(value = "/pagePointsDetails")
@ApiOperation("查询PointsDetail")
public ResultInfo pagePointsDetails(PointsDetailQueryCriteria criteria, Pageable pageable) {
return ResultInfo.successPage(pointsDetailService.queryAll(criteria,pageable));
}
@GetMapping(value = "/pageAvailablePoints")
@ApiOperation("查询PointsAvailable")
public ResultInfo pageAvailablePoints(PointsAvailableQueryCriteria criteria, Pageable pageable) {
PointsAvailableQueryType queryType = criteria.getQueryType();
// 可用
if (queryType == PointsAvailableQueryType.AVAILABLE_ONLY) {
criteria.setExpireTime(TimestampUtil.now());
}
return ResultInfo.successPage(pointsAvailableService.queryAll(criteria,pageable));
}
@GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}")
@ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用")
public ResultInfo cleanInvalidPointsAndCalculateCurrentPoints(@PathVariable("id") Long id) {
Long aLong = this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(id);
return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong);
}
@PostMapping(value = "/grantPointsByManual")
@ApiOperation("手动发放积分")
public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) {
Long memberId = tempPoints.getMemberId();
Long points = tempPoints.getPoints();
Assert.notNull(memberId,"memberId can't be null!");
Assert.notNull(points,"points can't be null!");
MemberDTO memberDTO = this.memberService.findById(memberId);
if (Objects.nonNull(memberDTO)) {
String code = memberDTO.getCode();
Assert.notNull(code,"code can't be null!");
tempPoints.setMemberCode(code);
this.pointsOperationService.grantPointsByManualByTempPoints(tempPoints);
}
return ResultInfo.success();
}
/**
* 通过用户账户id消耗积分
* @param tempIptvUser
* @return
*/
@PostMapping(value = "/customPointsByUserTvPlatformAccount")
@ApiOperation("通过大屏账户积分消耗")
public ResultInfo customPointsByUserTvPlatformAccount(@Validated @RequestBody TempCustomPointBean tempIptvUser) {
String platformAccount = tempIptvUser.getPlatformAccount();
Long points = tempIptvUser.getPoints();
Long activityId = tempIptvUser.getActivityId();
Integer evtType = tempIptvUser.getEvtType();
Long mediaId = tempIptvUser.getMediaId();
Long orderId = tempIptvUser.getOrderId();
Integer deviceType = tempIptvUser.getDeviceType();
TempPoints tempPoints = new TempPoints();
UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.nonNull(userTvDTO)) {
Long memberId = userTvDTO.getMemberId();
if (Objects.isNull(memberId)) {
return ResultInfo.failed("会员信息不存在");
}
MemberDTO memberDTO = this.memberService.findById(memberId);
tempPoints.setMemberCode(memberDTO.getCode());
tempPoints.setMemberId(memberId);
}
tempPoints.setPoints(points);
tempPoints.setDeviceType(deviceType);
tempPoints.setAppCode(LocalConstants.APP_CODE_CHONGQING_CHONGSHU_VIS);
tempPoints.setEvtType(evtType);
tempPoints.setActivityId(activityId);
tempPoints.setMediaId(mediaId);
tempPoints.setOrderId(orderId);
return this.customPoints(tempPoints);
}
/**
* 通过用户账户id消耗积分
* @param tempPoints
* @return
*/
@PostMapping(value = "/customPointsByUserId")
@ApiOperation("积分消耗")
public ResultInfo customPointsByUserId(@Validated @RequestBody TempPoints tempPoints) {
Long userId = tempPoints.getUserId();
// 设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
Integer deviceType = tempPoints.getDeviceType();
Long memberId = null;
if (deviceType == LocalConstants.DEVICE_VIS) {
memberId = this.getMemberIdByIpTvUserId(userId);
}
if (deviceType == LocalConstants.DEVICE_MOBILE) {
memberId = this.getMemberIdByWeiXinUserId(userId);
}
if (Objects.isNull(memberId)) {
return ResultInfo.failed("会员信息不存在");
}
tempPoints.setMemberId(memberId);
return this.customPoints(tempPoints);
}
/**
* 获取iptv账户对应的会员id
* @param userId
* @return
*/
private Long getMemberIdByIpTvUserId(Long userId) {
UserTvDTO userTvDTO = this.userTvService.findById(userId);
return userTvDTO.getMemberId();
}
/**
* 获取微信账户对应的会员id
* @param userId
* @return
*/
private Long getMemberIdByWeiXinUserId(Long userId) {
UserWeixinDTO userWeixinDTO = this.userWeixinService.findById(userId);
return userWeixinDTO.getMemberId();
}
@PostMapping(value = "/consumePoints")
@ApiOperation("积分消耗")
public ResultInfo customPoints(@Validated @RequestBody TempPoints tempPoints) {
Integer pointsType = tempPoints.getPointsType();
if (Objects.isNull(pointsType)) {
tempPoints.setPointsType(0);
}
CustomPointsResult b = this.pointsOperationService.customPoints(tempPoints);
String description = "操作成功";
if (!b.isResult()) {
description = "操作失败,积分不足";
}
return ResultInfo.success(Arrays.asList(b),description);
}
}