Kaynağa Gözat

修改活动作品预热和道具预热

silent 4 yıl önce
ebeveyn
işleme
3cf83dd820

+ 11 - 7
src/main/java/org/springblade/gateway/active_gateway/controller/AppActiveProductController.java

@@ -46,18 +46,22 @@ public class AppActiveProductController extends BladeController {
 
 	private final IActiveRecordService activeRecordService;
 
+	/**
+	 * 初始化作品(预热)
+	 */
 	@PostConstruct
-	public void init(){
+	public void init() {
 		//查询所有的活动列表
-		List<ActiveRecord> activeRecordList = activeRecordService.list();
-		for (ActiveRecord activeRecord : activeRecordList) {
+		for (ActiveRecord activeRecord : activeRecordService.list(
+			Wrappers.<ActiveRecord>lambdaQuery().select(ActiveRecord::getId))) {
 			//查询该活动的所有作品
 			List<ActiveProductRecord> activeProductRecordList = activeProductRecordService
 				.list(Wrappers.<ActiveProductRecord>lambdaQuery()
-				.eq(ActiveProductRecord::getActiveId, activeRecord.getId()));
-			if(ObjectUtils.isNotEmpty(activeProductRecordList) && activeProductRecordList.size()!=0){
+					.select(ActiveProductRecord::getId,ActiveProductRecord::getVoteCount)
+					.eq(ActiveProductRecord::getActiveId, activeRecord.getId()));
+			if (ObjectUtils.isNotEmpty(activeProductRecordList) && activeProductRecordList.size() != 0) {
 				Map<Object, Double> map = activeProductRecordList.stream().collect(Collectors.toMap(ele -> ele.getId(), ele -> Double.valueOf(ele.getVoteCount())));
-				ActiveProductUtil.addActiveCache(activeRecord.getId().toString(),map);
+				ActiveProductUtil.addActiveCache(activeRecord.getId().toString(), map);
 			}
 		}
 	}
@@ -69,7 +73,7 @@ public class AppActiveProductController extends BladeController {
 //	@PostMapping("/productHelp")
 	@ApiOperationSupport(order = 1)
 	@ApiOperation(value = "作品助力", notes = "传入activeHelpRecord")
-	public R<String> productHelp(@Valid ActiveHelpRecord activeHelpRecord, HttpServletRequest request){
+	public R<String> productHelp(@Valid ActiveHelpRecord activeHelpRecord, HttpServletRequest request) {
 		try {
 			//获取用户IP地址
 			activeHelpRecord.setIp(IPUtils.getRealIp(request));

+ 38 - 20
src/main/java/org/springblade/gateway/goods_gateway/controller/AppHelpGoodsController.java

@@ -1,5 +1,6 @@
 package org.springblade.gateway.goods_gateway.controller;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -13,12 +14,16 @@ import org.springblade.gateway.goods_gateway.util.HelpGoodsUtil;
 import org.springblade.payment.cmcc.request.CmccDectOrderRequest;
 import org.springblade.payment.cmcc.request.CmccPlaceOrderRequest;
 import org.springblade.payment.cmcc.util.CmccUtil;
+import org.springblade.sing.active.entity.ActiveRecord;
+import org.springblade.sing.active.service.IActiveRecordService;
+import org.springblade.sing.goods.entity.HelpGoods;
 import org.springblade.sing.goods.service.IHelpGoodsService;
 import org.springblade.sing.goods.vo.HelpGoodsVO;
 import org.springblade.sing.goods.wrapper.HelpGoodsWrapper;
 import org.springblade.sing.point.entity.CmccPointRecord;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.PostConstruct;
 import java.math.BigDecimal;
 import java.util.List;
 
@@ -36,6 +41,7 @@ import java.util.List;
 public class AppHelpGoodsController {
 	private final AppHelpGoodsService appHelpGoodsService;
 	private final IHelpGoodsService helpGoodsService;
+	private final IActiveRecordService activeRecordService;
 
 
 	/**
@@ -45,19 +51,19 @@ public class AppHelpGoodsController {
 	@PostMapping("/exchangeProps")
 	@ApiOperationSupport(order = 1)
 	@ApiOperation(value = "兑换道具", notes = "传入pointRecord")
-	public R<String> exchangeProps(@ApiParam(value = "道具ID",required = true) @RequestParam Long helpGoodsId,
-						   @ApiParam(value = "用户ID",required = true) @RequestParam Long userId,
-						   @ApiParam(value = "购买数量",required = true) @RequestParam BigDecimal num,
-						   @ApiParam(value = "作品ID",required = true) @RequestParam Long productId,
-						   CmccDectOrderRequest cmccDectOrderRequest){
+	public R<String> exchangeProps(@ApiParam(value = "道具ID", required = true) @RequestParam Long helpGoodsId,
+								   @ApiParam(value = "用户ID", required = true) @RequestParam Long userId,
+								   @ApiParam(value = "购买数量", required = true) @RequestParam BigDecimal num,
+								   @ApiParam(value = "作品ID", required = true) @RequestParam Long productId,
+								   CmccDectOrderRequest cmccDectOrderRequest) {
 		try {
 			CmccPointRecord cmccPointRecord = new CmccPointRecord();
 			cmccPointRecord.setHelpGoodsId(helpGoodsId);
 			cmccPointRecord.setUserId(userId);
 			cmccPointRecord.setNum(num);
 			//加锁
-			synchronized (cmccPointRecord.getUserId().toString().intern()){
-				appHelpGoodsService.exchangeProps(cmccPointRecord,cmccDectOrderRequest,productId);
+			synchronized (cmccPointRecord.getUserId().toString().intern()) {
+				appHelpGoodsService.exchangeProps(cmccPointRecord, cmccDectOrderRequest, productId);
 			}
 			return R.success("兑换成功");
 		} catch (Exception e) {
@@ -73,12 +79,12 @@ public class AppHelpGoodsController {
 	@PostMapping("/createPropsOrder")
 	@ApiOperationSupport(order = 1)
 	@ApiOperation(value = "创建道具订单", notes = "传入cmccPointRecord")
-	public R<String> createPropsOrder(@ApiParam(value = "道具ID",required = true) @RequestParam Long helpGoodsId,
-							  @ApiParam(value = "用户ID",required = true) @RequestParam Long userId,
-							  @ApiParam(value = "手机号码",required = true) @RequestParam String phone,
-							  @ApiParam(value = "购买数量",required = true) @RequestParam BigDecimal num,
-							  @ApiParam(value = "同盾设备指纹",required = true) @RequestParam String fingerprint,
-							  @ApiParam(value = "通付盾参数",required = true) @RequestParam String sessionId){
+	public R<String> createPropsOrder(@ApiParam(value = "道具ID", required = true) @RequestParam Long helpGoodsId,
+									  @ApiParam(value = "用户ID", required = true) @RequestParam Long userId,
+									  @ApiParam(value = "手机号码", required = true) @RequestParam String phone,
+									  @ApiParam(value = "购买数量", required = true) @RequestParam BigDecimal num,
+									  @ApiParam(value = "同盾设备指纹", required = true) @RequestParam String fingerprint,
+									  @ApiParam(value = "通付盾参数", required = true) @RequestParam String sessionId) {
 		try {
 			CmccPlaceOrderRequest cmccPlaceOrderRequest = CmccPlaceOrderRequest
 				.builder()
@@ -107,8 +113,8 @@ public class AppHelpGoodsController {
 	@PostMapping("/sendCmccSms")
 	@ApiOperationSupport(order = 1)
 	@ApiOperation(value = "发送验证码", notes = "传入cmccPlaceOrderRequest")
-	public R<String> sendCmccSms(@ApiParam(value = "手机号码",required = true) @RequestParam String mobile,
-						 @ApiParam(value = "订单号ID",required = true) @RequestParam String outOrderId){
+	public R<String> sendCmccSms(@ApiParam(value = "手机号码", required = true) @RequestParam String mobile,
+								 @ApiParam(value = "订单号ID", required = true) @RequestParam String outOrderId) {
 		try {
 			CmccPlaceOrderRequest cmccPlaceOrderRequest = CmccPlaceOrderRequest
 				.builder()
@@ -124,15 +130,27 @@ public class AppHelpGoodsController {
 	}
 
 	/**
-	 * 分页 助力商城
+	 * 初始化道具缓存(预热)
+	 */
+	@PostConstruct
+	public void init() {
+		for (ActiveRecord activeRecord : activeRecordService.list(
+			Wrappers.<ActiveRecord>lambdaQuery().select(ActiveRecord::getId))) {
+			HelpGoodsUtil.setHelpGoodsListCache(activeRecord.getId(),
+				helpGoodsService.list(Wrappers.<HelpGoods>lambdaQuery().eq(HelpGoods::getActiveId, activeRecord.getId())));
+		}
+	}
+
+	/**
+	 * 获取道具助力列表
 	 */
 	@GetMapping("/getHelpGoodsList")
 	@ApiOperationSupport(order = 2)
 	@ApiOperation(value = "获取道具助力列表", notes = "传入helpGoods")
-	public R<List<HelpGoodsVO>> getHelpGoodsList(@ApiParam(value = "活动ID",required = true) @RequestParam Long activeId,
-									  @ApiParam(value = "用户ID",required = true) @RequestParam Long userId,
-									  @ApiParam(value = "作品ID",required = true) @RequestParam Long productId) {
-		return R.data(HelpGoodsWrapper.build(userId,productId)
+	public R<List<HelpGoodsVO>> getHelpGoodsList(@ApiParam(value = "活动ID", required = true) @RequestParam Long activeId,
+												 @ApiParam(value = "用户ID", required = true) @RequestParam Long userId,
+												 @ApiParam(value = "作品ID", required = true) @RequestParam Long productId) {
+		return R.data(HelpGoodsWrapper.build(userId, productId)
 			.listVO(HelpGoodsUtil.getHelpGoodsList(activeId)));
 	}
 }