Commit 07430150 074301509e9165f2eef10f24782ec0159e47ea89 by xianghan

1.优化

1 parent 79d9e9c5
...@@ -84,6 +84,10 @@ public class PointsDetail implements Serializable { ...@@ -84,6 +84,10 @@ public class PointsDetail implements Serializable {
84 @Column(name = "description", nullable = false) 84 @Column(name = "description", nullable = false)
85 private String description; 85 private String description;
86 86
87 // 商品id
88 @Column(name = "item_id")
89 private Long itemId;
90
87 // 创建时间 91 // 创建时间
88 @CreatedDate 92 @CreatedDate
89 @Column(name = "create_time") 93 @Column(name = "create_time")
......
...@@ -54,6 +54,9 @@ public class PointsDetailDTO implements Serializable { ...@@ -54,6 +54,9 @@ public class PointsDetailDTO implements Serializable {
54 // 积分变化描述,用于管理侧显示 54 // 积分变化描述,用于管理侧显示
55 private String description; 55 private String description;
56 56
57 // 商品id
58 private Long itemId;
59
57 // 创建时间 60 // 创建时间
58 private Timestamp createTime; 61 private Timestamp createTime;
59 62
......
1 package com.topdraw.business.module.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 }
...@@ -56,7 +56,6 @@ public class TempRights { ...@@ -56,7 +56,6 @@ public class TempRights {
56 56
57 /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */ 57 /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */
58 @Transient 58 @Transient
59 @NotNull(message = "设备类型不得为空")
60 protected Integer deviceType; 59 protected Integer deviceType;
61 60
62 /** 应用code(表示当前用户对应应用的标识) */ 61 /** 应用code(表示当前用户对应应用的标识) */
......
1 package com.topdraw.business.process.rest; 1 package com.topdraw.business.process.rest;
2 2
3 import com.topdraw.annotation.AnonymousAccess; 3 import com.topdraw.annotation.AnonymousAccess;
4 import com.topdraw.aop.log.Log;
4 import com.topdraw.business.module.member.service.MemberService; 5 import com.topdraw.business.module.member.service.MemberService;
5 import com.topdraw.business.module.member.service.dto.MemberDTO; 6 import com.topdraw.business.module.member.service.dto.MemberDTO;
6 import com.topdraw.business.module.points.detail.service.PointsDetailService;
7 import com.topdraw.business.module.points.detail.service.dto.PointsDetailQueryCriteria;
8 import com.topdraw.business.module.user.iptv.service.UserTvService; 7 import com.topdraw.business.module.user.iptv.service.UserTvService;
9 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; 8 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
10 import com.topdraw.business.module.user.weixin.service.UserWeixinService; 9 import com.topdraw.business.module.user.weixin.service.UserWeixinService;
...@@ -15,10 +14,12 @@ import com.topdraw.business.process.service.dto.CustomPointsResult; ...@@ -15,10 +14,12 @@ import com.topdraw.business.process.service.dto.CustomPointsResult;
15 import com.topdraw.business.process.service.PointsOperationService; 14 import com.topdraw.business.process.service.PointsOperationService;
16 import com.topdraw.common.ResultInfo; 15 import com.topdraw.common.ResultInfo;
17 import com.topdraw.config.LocalConstants; 16 import com.topdraw.config.LocalConstants;
17 import com.topdraw.exception.BadRequestException;
18 import com.topdraw.exception.GlobeExceptionMsg;
18 import io.swagger.annotations.Api; 19 import io.swagger.annotations.Api;
19 import io.swagger.annotations.ApiOperation; 20 import io.swagger.annotations.ApiOperation;
21 import lombok.extern.slf4j.Slf4j;
20 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.data.domain.Pageable;
22 import org.springframework.util.Assert; 23 import org.springframework.util.Assert;
23 import org.springframework.validation.annotation.Validated; 24 import org.springframework.validation.annotation.Validated;
24 import org.springframework.web.bind.annotation.*; 25 import org.springframework.web.bind.annotation.*;
...@@ -33,6 +34,7 @@ import java.util.Objects; ...@@ -33,6 +34,7 @@ import java.util.Objects;
33 @Api(tags = "PointsOperation管理") 34 @Api(tags = "PointsOperation管理")
34 @RestController 35 @RestController
35 @RequestMapping("/uce/pointsOperation") 36 @RequestMapping("/uce/pointsOperation")
37 @Slf4j
36 public class PointsOperationController { 38 public class PointsOperationController {
37 39
38 @Autowired 40 @Autowired
...@@ -42,10 +44,9 @@ public class PointsOperationController { ...@@ -42,10 +44,9 @@ public class PointsOperationController {
42 @Autowired 44 @Autowired
43 private UserWeixinService userWeixinService; 45 private UserWeixinService userWeixinService;
44 @Autowired 46 @Autowired
45 private PointsDetailService pointsDetailService;
46 @Autowired
47 private PointsOperationService pointsOperationService; 47 private PointsOperationService pointsOperationService;
48 48
49 @Log("清除过期积分并计算总积分,供客户端会员查询积分时调用")
49 @GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}") 50 @GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}")
50 @ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用") 51 @ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用")
51 @AnonymousAccess 52 @AnonymousAccess
...@@ -54,10 +55,11 @@ public class PointsOperationController { ...@@ -54,10 +55,11 @@ public class PointsOperationController {
54 return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong); 55 return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong);
55 } 56 }
56 57
57 @PostMapping(value = "/grantPointsByManual") 58 @Log("手动发放积分")
59 @PostMapping(value = "/addPoints")
58 @ApiOperation("手动发放积分") 60 @ApiOperation("手动发放积分")
59 @AnonymousAccess 61 @AnonymousAccess
60 public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { 62 public ResultInfo addPoints(@Validated @RequestBody TempPoints tempPoints) {
61 Long memberId = tempPoints.getMemberId(); 63 Long memberId = tempPoints.getMemberId();
62 Long points = tempPoints.getPoints(); 64 Long points = tempPoints.getPoints();
63 Assert.notNull(memberId,"memberId can't be null!"); 65 Assert.notNull(memberId,"memberId can't be null!");
...@@ -172,6 +174,33 @@ public class PointsOperationController { ...@@ -172,6 +174,33 @@ public class PointsOperationController {
172 return ResultInfo.success(Arrays.asList(b),description); 174 return ResultInfo.success(Arrays.asList(b),description);
173 } 175 }
174 176
177 @Log("积分兑换商品")
178 @PostMapping(value = "/consumeItemPoints")
179 @ApiOperation("积分兑换商品")
180 @AnonymousAccess
181 public ResultInfo consumeItemPoints(@Validated @RequestBody TempPoints tempPoints) {
182 log.info("pointsOperation ==>> consumeItemPoints ==>> param ==>> {}", tempPoints);
183 Long memberId = tempPoints.getMemberId();
184 Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL);
185 Long points = tempPoints.getPoints();
186 if (Objects.isNull(points) || points <= 0) {
187 log.info("points ==>> {}", points);
188 throw new BadRequestException("points error");
189 }
190 Long itemId = tempPoints.getItemId();
191 Assert.notNull(itemId, "itemId can't be null");
192
193 // 积分兑换商品
194 tempPoints.setEvtType(30);
195 tempPoints.setPointsType(0);
196 CustomPointsResult b = this.pointsOperationService.customPoints(tempPoints);
197 String description = "操作成功";
198 if (!b.isResult()) {
199 description = "操作失败,积分不足";
200 }
201 return ResultInfo.success(Arrays.asList(b),description);
202 }
203
175 204
176 205
177 } 206 }
......
...@@ -74,6 +74,8 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -74,6 +74,8 @@ public class PointsOperationServiceImpl implements PointsOperationService {
74 @AsyncMqSend 74 @AsyncMqSend
75 public void asyncPointsAvailable(PointsAvailable pointsAvailable) {} 75 public void asyncPointsAvailable(PointsAvailable pointsAvailable) {}
76 @AsyncMqSend 76 @AsyncMqSend
77 public void asyncDeletePointsAvailable(PointsAvailable pointsAvailable) {}
78 @AsyncMqSend
77 public void asyncPointsDetail(PointsDetail pointsDetail) {} 79 public void asyncPointsDetail(PointsDetail pointsDetail) {}
78 80
79 @Override 81 @Override
...@@ -111,6 +113,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -111,6 +113,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
111 this.redisUtils.doLock("member::id::" + memberId.toString()); 113 this.redisUtils.doLock("member::id::" + memberId.toString());
112 //1.删除过期的积分 114 //1.删除过期的积分
113 this.cleanInvalidAvailablePointsByMemberId(memberId); 115 this.cleanInvalidAvailablePointsByMemberId(memberId);
116 log.info("删除过期的积分 ==>> cleanInvalidAvailablePointsByMemberId ==>> ");
114 // 1.判断可用积分是否够用 117 // 1.判断可用积分是否够用
115 boolean b = this.checkAvailablePoints(tempPoints); 118 boolean b = this.checkAvailablePoints(tempPoints);
116 // 3.当前可用总积分 119 // 3.当前可用总积分
...@@ -123,6 +126,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -123,6 +126,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
123 this.customAvailablePoints(tempPoints, pointsAvailableDTOS); 126 this.customAvailablePoints(tempPoints, pointsAvailableDTOS);
124 // 3.添加积分明细 127 // 3.添加积分明细
125 this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints); 128 this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints);
129 log.info("添加积分明细 ==>> doInsertTrPointsDetailByAvailablePointsMap ==>> ");
126 // 4.更新可用积分表,超过的删除,剩余的新增 130 // 4.更新可用积分表,超过的删除,剩余的新增
127 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); 131 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints);
128 // 5.即将过期的积分 132 // 5.即将过期的积分
...@@ -164,6 +168,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -164,6 +168,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
164 for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS1) { 168 for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS1) {
165 totalCustomAvailablePoints = (totalCustomAvailablePoints+pointsAvailableDTO.getPoints()); 169 totalCustomAvailablePoints = (totalCustomAvailablePoints+pointsAvailableDTO.getPoints());
166 this.pointsAvailableService.delete4Custom(pointsAvailableDTO.getId()); 170 this.pointsAvailableService.delete4Custom(pointsAvailableDTO.getId());
171
172 PointsAvailable pointsAvailable = new PointsAvailable();
173 BeanUtils.copyProperties(pointsAvailableDTO, pointsAvailable);
174 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncDeletePointsAvailable(pointsAvailable);
167 } 175 }
168 } 176 }
169 177
...@@ -172,10 +180,12 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -172,10 +180,12 @@ public class PointsOperationServiceImpl implements PointsOperationService {
172 if (!CollectionUtils.isEmpty(pointsAvailableDTOS2)) { 180 if (!CollectionUtils.isEmpty(pointsAvailableDTOS2)) {
173 PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS2.get(0); 181 PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS2.get(0);
174 PointsAvailable pointsAvailable = new PointsAvailable(); 182 PointsAvailable pointsAvailable = new PointsAvailable();
175 BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailable); 183 BeanUtils.copyProperties(pointsAvailableDTO, pointsAvailable);
176 pointsAvailable.setId(null); 184 pointsAvailable.setId(null);
177 pointsAvailable.setCode(String.valueOf(IdWorker.generator())); 185 pointsAvailable.setCode(String.valueOf(IdWorker.generator()));
178 this.pointsAvailableService.create4Custom(pointsAvailable); 186 this.pointsAvailableService.create4Custom(pointsAvailable);
187
188 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable);
179 } 189 }
180 } 190 }
181 191
...@@ -198,12 +208,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -198,12 +208,13 @@ public class PointsOperationServiceImpl implements PointsOperationService {
198 PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS.get(0); 208 PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS.get(0);
199 Long memberId = pointsAvailableDTO.getMemberId(); 209 Long memberId = pointsAvailableDTO.getMemberId();
200 210
201 TempPoints tempPoints1 = new TempPoints(); 211 TempPoints _tempPoints = new TempPoints();
202 BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1); 212 BeanUtils.copyProperties(pointsAvailableDTO, _tempPoints);
203 BeanUtils.copyProperties(tempPoints,tempPoints1); 213 BeanUtils.copyProperties(tempPoints, _tempPoints);
204 tempPoints1.setPoints(-(Math.abs(points))); 214 _tempPoints.setPoints(-(Math.abs(points)));
205 Long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints); 215 Long totalPoints = this.calculateTotalPoints(_tempPoints, currentPoints);
206 this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints,totalPoints); 216
217 this.doInsertTrPointsDetail(memberId, _tempPoints, currentPoints, totalPoints);
207 } 218 }
208 } 219 }
209 220
...@@ -244,7 +255,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -244,7 +255,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
244 long beyond = points1_ - points; 255 long beyond = points1_ - points;
245 // 新增 256 // 新增
246 PointsAvailableDTO pointsAvailableDTO2 = new PointsAvailableDTO(); 257 PointsAvailableDTO pointsAvailableDTO2 = new PointsAvailableDTO();
247 BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO2); 258 BeanUtils.copyProperties(pointsAvailableDTO, pointsAvailableDTO2);
248 pointsAvailableDTO2.setPoints(beyond); 259 pointsAvailableDTO2.setPoints(beyond);
249 pointsAvailableDTOS2.add(pointsAvailableDTO2); 260 pointsAvailableDTOS2.add(pointsAvailableDTO2);
250 261
...@@ -252,7 +263,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -252,7 +263,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
252 long suit = points1 - beyond; 263 long suit = points1 - beyond;
253 // 扣除 264 // 扣除
254 PointsAvailableDTO pointsAvailableDTO1 = new PointsAvailableDTO(); 265 PointsAvailableDTO pointsAvailableDTO1 = new PointsAvailableDTO();
255 BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO1); 266 BeanUtils.copyProperties(pointsAvailableDTO, pointsAvailableDTO1);
256 pointsAvailableDTO1.setPoints(suit); 267 pointsAvailableDTO1.setPoints(suit);
257 pointsAvailableDTOS1.add(pointsAvailableDTO1); 268 pointsAvailableDTOS1.add(pointsAvailableDTO1);
258 269
...@@ -371,7 +382,12 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -371,7 +382,12 @@ public class PointsOperationServiceImpl implements PointsOperationService {
371 * @param pointsAvailableDTO 382 * @param pointsAvailableDTO
372 */ 383 */
373 private void doDeleteInvalidAvailablePoints(PointsAvailableDTO pointsAvailableDTO) { 384 private void doDeleteInvalidAvailablePoints(PointsAvailableDTO pointsAvailableDTO) {
385
374 this.pointsAvailableService.delete4Custom(pointsAvailableDTO.getId()); 386 this.pointsAvailableService.delete4Custom(pointsAvailableDTO.getId());
387
388 PointsAvailable pointsAvailable = new PointsAvailable();
389 BeanUtils.copyProperties(pointsAvailableDTO, pointsAvailable);
390 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncDeletePointsAvailable(pointsAvailable);
375 } 391 }
376 392
377 /** 393 /**
...@@ -381,6 +397,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -381,6 +397,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
381 private void doCreatePointsDetail(PointsAvailableDTO pointsAvailableDTO) { 397 private void doCreatePointsDetail(PointsAvailableDTO pointsAvailableDTO) {
382 398
383 Long memberId = pointsAvailableDTO.getMemberId(); 399 Long memberId = pointsAvailableDTO.getMemberId();
400 MemberDTO memberDTO = this.memberService.findById(memberId);
384 // 原始积分 401 // 原始积分
385 long availablePoints = this.pointsAvailableService.findTotalPointsByMemberId(memberId);//this.findAvailablePointsByMemberId(memberId); 402 long availablePoints = this.pointsAvailableService.findTotalPointsByMemberId(memberId);//this.findAvailablePointsByMemberId(memberId);
386 // 过期积分 403 // 过期积分
...@@ -399,7 +416,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -399,7 +416,11 @@ public class PointsOperationServiceImpl implements PointsOperationService {
399 pointsDetail.setEvtType(99); 416 pointsDetail.setEvtType(99);
400 pointsDetail.setCreateTime(TimestampUtil.now()); 417 pointsDetail.setCreateTime(TimestampUtil.now());
401 pointsDetail.setUpdateTime(TimestampUtil.now()); 418 pointsDetail.setUpdateTime(TimestampUtil.now());
419 pointsDetail.setMemberCode(memberDTO.getCode());
402 this.pointsDetailService.create4Custom(pointsDetail); 420 this.pointsDetailService.create4Custom(pointsDetail);
421
422 log.info("asyncPointsDetail ==>> pointsDetail ==>> {}",pointsDetail);
423 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail);
403 } 424 }
404 425
405 /** 426 /**
...@@ -544,11 +565,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -544,11 +565,13 @@ public class PointsOperationServiceImpl implements PointsOperationService {
544 */ 565 */
545 private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints, Long currentPoints, Long totalPoints){ 566 private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints, Long currentPoints, Long totalPoints){
546 567
568 MemberDTO memberDTO = this.memberService.findById(memberId);
569
547 PointsDetail pointsDetail = new PointsDetail(); 570 PointsDetail pointsDetail = new PointsDetail();
548 BeanUtils.copyProperties(tempPoints,pointsDetail); 571 BeanUtils.copyProperties(tempPoints, pointsDetail);
549 pointsDetail.setId(null); 572 pointsDetail.setId(null);
550 pointsDetail.setMemberId(memberId); 573 pointsDetail.setMemberId(memberId);
551 pointsDetail.setMemberCode(tempPoints.getMemberCode()); 574 pointsDetail.setMemberCode(memberDTO.getCode());
552 pointsDetail.setCode(String.valueOf(IdWorker.generator())); 575 pointsDetail.setCode(String.valueOf(IdWorker.generator()));
553 pointsDetail.setPoints(tempPoints.getPoints()); 576 pointsDetail.setPoints(tempPoints.getPoints());
554 pointsDetail.setOriginalPoints(currentPoints); 577 pointsDetail.setOriginalPoints(currentPoints);
......
...@@ -50,7 +50,7 @@ public class PointsOperationControllerTest extends BaseTest { ...@@ -50,7 +50,7 @@ public class PointsOperationControllerTest extends BaseTest {
50 tempPoints.setEvtType(1); 50 tempPoints.setEvtType(1);
51 tempPoints.setActivityId(1L); 51 tempPoints.setActivityId(1L);
52 String s = JSON.toJSONString(tempPoints); 52 String s = JSON.toJSONString(tempPoints);
53 ResultInfo byId = this.pointsOperationController.grantPointsByManual(tempPoints); 53 ResultInfo byId = this.pointsOperationController.addPoints(tempPoints);
54 LOG.info("===>>>"+byId); 54 LOG.info("===>>>"+byId);
55 } 55 }
56 56
......