Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

xiaoqiang 4 лет назад
Родитель
Сommit
0a9fe5c3e1

+ 55 - 19
src/main/java/org/springblade/gateway/active_gateway/controller/AppActiveProductController.java

@@ -1,13 +1,32 @@
 package org.springblade.gateway.active_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;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springblade.common.utils.IPUtils;
 import org.springblade.core.boot.ctrl.BladeController;
+import org.springblade.core.log.annotation.ApiLog;
+import org.springblade.core.tool.api.R;
 import org.springblade.gateway.active_gateway.service.AppActiveProductService;
+import org.springblade.gateway.active_gateway.util.ActiveProductUtil;
+import org.springblade.sing.active.entity.ActiveHelpRecord;
+import org.springblade.sing.active.entity.ActiveProductRecord;
+import org.springblade.sing.active.entity.ActiveRecord;
+import org.springblade.sing.active.service.IActiveProductRecordService;
+import org.springblade.sing.active.service.IActiveRecordService;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.PostConstruct;
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 /**
  * @Author: Silent
  * @Description
@@ -20,25 +39,42 @@ import org.springframework.web.bind.annotation.RestController;
 @Api(value = "助力", tags = "助力接口")
 @Slf4j
 public class AppActiveProductController extends BladeController {
-	private AppActiveProductService activeService;
+	private final AppActiveProductService activeService;
 
-//	/**
-//	 * 作品助力
-//	 */
-//	@ApiLog("作品助力")
-//	@PostMapping("/productHelp")
-//	@ApiOperationSupport(order = 1)
-//	@ApiOperation(value = "作品助力", notes = "传入activeHelpRecord")
-//	public R<String> productHelp(@Valid ActiveHelpRecord activeHelpRecord, HttpServletRequest request){
-//		try {
-//			//获取用户IP地址
-//			activeHelpRecord.setIp(IPUtils.getRealIp(request));
-//			activeService.activeHelp(activeHelpRecord);
-//			return R.success("助力成功!");
-//		} catch (Exception e) {
-//			log.error(e.getMessage());
-//			return R.fail(e.getMessage());
-//		}
-//	}
+	private final IActiveProductRecordService activeProductRecordService;
+
+	private final IActiveRecordService activeRecordService;
 
+	@PostConstruct
+	public void init(){
+		//查询所有的活动列表
+		List<ActiveRecord> activeRecordList = activeRecordService.list();
+		for (ActiveRecord activeRecord : activeRecordList) {
+			//查询该活动的所有作品
+			List<ActiveProductRecord> activeProductRecordList = activeProductRecordService
+				.list(Wrappers.<ActiveProductRecord>lambdaQuery()
+				.eq(ActiveProductRecord::getActiveId, activeRecord.getId()));
+			Map<Object, Double> map = activeProductRecordList.stream().collect(Collectors.toMap(ele -> ele.getId(), ele -> ele.getHeatValue().doubleValue()));
+			ActiveProductUtil.addActiveCache(activeRecord.getId().toString(),map);
+		}
+	}
+
+	/**
+	 * 作品助力
+	 */
+	@ApiLog("作品助力")
+//	@PostMapping("/productHelp")
+	@ApiOperationSupport(order = 1)
+	@ApiOperation(value = "作品助力", notes = "传入activeHelpRecord")
+	public R<String> productHelp(@Valid ActiveHelpRecord activeHelpRecord, HttpServletRequest request){
+		try {
+			//获取用户IP地址
+			activeHelpRecord.setIp(IPUtils.getRealIp(request));
+			activeService.activeHelp(activeHelpRecord);
+			return R.success("助力成功!");
+		} catch (Exception e) {
+			log.error(e.getMessage());
+			return R.fail(e.getMessage());
+		}
+	}
 }

+ 26 - 1
src/main/java/org/springblade/gateway/active_gateway/util/ActiveProductUtil.java

@@ -1,10 +1,13 @@
 package org.springblade.gateway.active_gateway.util;
 
+import org.springblade.common.utils.SpringContextHolder;
 import org.springblade.core.redis.cache.BladeRedis;
 import org.springblade.core.tool.utils.SpringUtil;
 import org.springblade.gateway.active_gateway.constant.ActiveProductConstant;
 import org.springblade.sing.active.entity.ActiveProductRecord;
 
+import java.util.Map;
+
 /**
  * @Author: Silent
  * @Description
@@ -12,7 +15,7 @@ import org.springblade.sing.active.entity.ActiveProductRecord;
  * @Modified By:
  */
 public class ActiveProductUtil {
-	private static final BladeRedis bladeRedis = SpringUtil.getBean(BladeRedis.class);
+	private static final BladeRedis bladeRedis = SpringContextHolder.getBean(BladeRedis.class);
 
 	/**
 	 * 添加作品排名
@@ -29,6 +32,8 @@ public class ActiveProductUtil {
 
 	/**
 	 * 删除作品排行
+	 * @param activeProductRecord
+	 * @return
 	 */
 	public static Long delProductRank(ActiveProductRecord activeProductRecord){
 		//先移除
@@ -36,6 +41,26 @@ public class ActiveProductUtil {
 			activeProductRecord.getId());
 	}
 
+	/**
+	 * 删除活动缓存
+	 * @param activeId
+	 * @return
+	 */
+	public static boolean delActiveCache(String activeId){
+		return bladeRedis.del(new StringBuilder(ActiveProductConstant.PRODUCT_SORT_CACHE_KEY).append(":").append(activeId).toString());
+	}
+
+	/**
+	 * 添加活动缓存
+	 * @param activeId
+	 * @param activeMap
+	 * @return
+	 */
+	public static Long addActiveCache(String activeId, Map<Object,Double> activeMap){
+		delActiveCache(activeId);
+		return bladeRedis.zAdd(new StringBuilder(ActiveProductConstant.PRODUCT_SORT_CACHE_KEY).append(":").append(activeId).toString(),activeMap);
+	}
+
 	/**
 	 * 添加累计加热力值
 	 * @param activeId 活动id

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

@@ -104,7 +104,7 @@ public class AppHelpGoodsController {
 	@ApiLog("发送验证码")
 	@PostMapping("/sendCmccSms")
 	@ApiOperationSupport(order = 1)
-	@ApiOperation(value = "创建道具订单", notes = "传入cmccPlaceOrderRequest")
+	@ApiOperation(value = "发送验证码", notes = "传入cmccPlaceOrderRequest")
 	public R<String> sendCmccSms(@ApiParam(value = "手机号码",required = true) @RequestParam String mobile,
 						 @ApiParam(value = "订单号ID",required = true) @RequestParam String outOrderId){
 		try {

+ 4 - 4
src/main/java/org/springblade/sing/goods/controller/HelpGoodsController.java

@@ -56,9 +56,9 @@ public class HelpGoodsController extends BladeController {
 	@GetMapping("/detail")
 	@ApiOperationSupport(order = 1)
 	@ApiOperation(value = "详情", notes = "传入helpGoods")
-	public R<HelpGoodsVO> detail(HelpGoods helpGoods,Long userId) {
+	public R<HelpGoodsVO> detail(HelpGoods helpGoods,Long userId,Long productId) {
 		HelpGoods detail = helpGoodsService.getOne(Condition.getQueryWrapper(helpGoods));
-		return R.data(HelpGoodsWrapper.build(userId).entityVO(detail));
+		return R.data(HelpGoodsWrapper.build(userId,productId).entityVO(detail));
 	}
 
 	/**
@@ -67,9 +67,9 @@ public class HelpGoodsController extends BladeController {
 	@GetMapping("/list")
 	@ApiOperationSupport(order = 2)
 	@ApiOperation(value = "分页", notes = "传入helpGoods")
-	public R<IPage<HelpGoodsVO>> list(HelpGoods helpGoods, Query query,Long userId) {
+	public R<IPage<HelpGoodsVO>> list(HelpGoods helpGoods, Query query,Long userId,Long productId) {
 		IPage<HelpGoods> pages = helpGoodsService.page(Condition.getPage(query), Condition.getQueryWrapper(helpGoods));
-		return R.data(HelpGoodsWrapper.build(userId).pageVO(pages));
+		return R.data(HelpGoodsWrapper.build(userId,productId).pageVO(pages));
 	}
 
 

+ 34 - 4
src/main/java/org/springblade/sing/goods/wrapper/HelpGoodsWrapper.java

@@ -16,15 +16,23 @@
  */
 package org.springblade.sing.goods.wrapper;
 
+import cn.hutool.core.map.MapUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.ObjectUtils;
+import org.springblade.common.utils.BeanPropertyUtil;
 import org.springblade.common.utils.SpringContextHolder;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.core.tool.utils.DateUtil;
 import org.springblade.gateway.goods_gateway.service.AppHelpGoodsService;
+import org.springblade.sing.active.entity.ActiveHelpRecord;
+import org.springblade.sing.active.service.IActiveHelpRecordService;
 import org.springblade.sing.goods.entity.HelpGoods;
 import org.springblade.sing.goods.vo.HelpGoodsVO;
+import org.springblade.sing.point.entity.PointRecord;
 
+import java.util.Map;
 import java.util.Objects;
 
 /**
@@ -36,12 +44,16 @@ import java.util.Objects;
 @AllArgsConstructor
 public class HelpGoodsWrapper extends BaseEntityWrapper<HelpGoods, HelpGoodsVO>  {
 
+	private final static AppHelpGoodsService appHelpGoodsService = SpringContextHolder.getBean(AppHelpGoodsService.class);
+
+	private final static IActiveHelpRecordService activeHelpRecordService = SpringContextHolder.getBean(IActiveHelpRecordService.class);
+
 	private final Long userId;
 
-	private final static AppHelpGoodsService appHelpGoodsService = SpringContextHolder.getBean(AppHelpGoodsService.class);
+	private final Long productId;
 
-	public static HelpGoodsWrapper build(Long userId) {
-		return new HelpGoodsWrapper(userId);
+	public static HelpGoodsWrapper build(Long userId,Long productId) {
+		return new HelpGoodsWrapper(userId,productId);
  	}
 
 	@Override
@@ -50,7 +62,25 @@ public class HelpGoodsWrapper extends BaseEntityWrapper<HelpGoods, HelpGoodsVO>
 
 		//查询用户剩余道具次数
 		if(ObjectUtils.isNotEmpty(userId)){
-			helpGoodsVO.setRemainCount(helpGoodsVO.getTotal() - appHelpGoodsService.userHelpGoodsExchangeCount(userId, helpGoodsVO.getId()));
+			//判断总次数
+			long total = helpGoodsVO.getTotal() - appHelpGoodsService.userHelpGoodsExchangeCount(userId, helpGoodsVO.getId());
+			if(!Long.valueOf(0L).equals(total)){
+				Map<String, Object> map = activeHelpRecordService.getMap(Wrappers.<ActiveHelpRecord>query().select(new StringBuilder("ifnull(sum(")
+						.append(BeanPropertyUtil.getFieldNameToUnder(ActiveHelpRecord::getVoteCount))
+						.append("),0) as count")
+						.toString())
+					.lambda()
+					.eq(ActiveHelpRecord::getProductId, productId) //判断作品ID
+					.eq(ActiveHelpRecord::getUserId, userId)    //判断用户ID
+					.eq(ActiveHelpRecord::getHelpGoodsId, helpGoodsVO.getId()) //判断道具ID
+					.last(new StringBuilder("and date_format(")
+						.append(BeanPropertyUtil.getFieldNameToUnder(PointRecord::getCreateTime))
+						.append(",\"%Y-%m-%d\")=\"")
+						.append(DateUtil.format(DateUtil.now(), "yyyy-MM-dd").trim()).append("\"").toString()));
+				helpGoodsVO.setRemainCount(helpGoodsVO.getActiveVote() - MapUtil.getLong(map, "count"));
+			}else{
+				helpGoodsVO.setRemainCount(0L);
+			}
 		}
 		//User createUser = UserCache.getUser(helpGoods.getCreateUser());
 		//User updateUser = UserCache.getUser(helpGoods.getUpdateUser());