|
|
@@ -98,54 +98,40 @@ public class AppActiveProductServiceImpl implements AppActiveProductService {
|
|
|
throw new AppActiveProductException("活动已结束哦~");
|
|
|
}
|
|
|
|
|
|
- //判断该用户对该活动助力是否达到上限(-1表示无上限)
|
|
|
- if (!Long.valueOf(-1).equals(helpGoods.getActiveVote())) {
|
|
|
- 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, activeProductRecord.getId()) //判断作品ID
|
|
|
- .eq(ActiveHelpRecord::getUserId, loginUser.getId()) //判断用户ID
|
|
|
- .eq(ActiveHelpRecord::getHelpGoodsId, helpGoods.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()));
|
|
|
- if ((MapUtil.getLong(map, "count") + activeHelpRecord.getVoteCount()) > helpGoods.getActiveVote()) {
|
|
|
- throw new HelpGoodsException("您今日使用该道具对该活动投票次数超过上限");
|
|
|
- }
|
|
|
- }
|
|
|
+ //判断用户使用该道具对该活动助力次数是否到达上限
|
|
|
+ userHelpCountCheck(activeHelpRecord, activeProductRecord, loginUser, helpGoods);
|
|
|
|
|
|
//获取平台参数配置
|
|
|
ActiveSettingDto activeSetting = platformSettingUtil.getActiveSetting();
|
|
|
Assert.notNull(activeSetting, "平台没有配置投票参数");
|
|
|
|
|
|
- //判断是否普法积分
|
|
|
- if (ObjectUtils.isNotEmpty(activeSetting.getVoteAndPointRate()) && !activeSetting.getVoteAndPointRate().equals(BigDecimal.ZERO)) {
|
|
|
- //修改普法积分(票数*积分比例+原有积分)
|
|
|
- BigDecimal puFaPoint = activeSetting.getVoteAndPointRate()
|
|
|
- .multiply(BigDecimal.valueOf(activeHelpRecord.getVoteCount()));
|
|
|
- //添加普法积分赠送记录=>赠送给投票的用户
|
|
|
- PointRecord pointRecord = new PointRecord();
|
|
|
- pointRecord.setPoint(BigDecimal.valueOf(puFaPoint.doubleValue())); //必须克隆对象,防止事务状态下,使用同一个对象地址
|
|
|
- pointRecord.setPointType(PointTypeEnum.PUFA_POINT_SEND);
|
|
|
- pointRecord.setActiveProductId(activeHelpRecord.getProductId());
|
|
|
- pointRecord.setUserId(activeHelpRecord.getUserId());
|
|
|
- Assert.notNull(pointRecordService.save(pointRecord), "投票失败");
|
|
|
- loginUser.setPufaPoint(puFaPoint.add(loginUser.getPufaPoint()));
|
|
|
- }
|
|
|
+ //更新用户普法积分
|
|
|
+ userPuFaPointUpdate(activeHelpRecord, loginUser, activeSetting);
|
|
|
|
|
|
- //修改投票用户信息
|
|
|
- Assert.isTrue(loginUserService.updateById(loginUser), "投票失败");
|
|
|
+ //更新活动作品的票数和热力值
|
|
|
+ updateProductVoteAndHeat(activeHelpRecord, activeProductRecord, activeSetting);
|
|
|
|
|
|
+ //修改活动作品信息
|
|
|
+ Assert.isTrue(activeProductRecordService.updateById(activeProductRecord));
|
|
|
+
|
|
|
+ //添加活动记录
|
|
|
+ Assert.isTrue(activeHelpRecordService.save(activeHelpRecord), "投票失败");
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新活动作品的票数和热力值
|
|
|
+ * @param activeHelpRecord
|
|
|
+ * @param activeProductRecord
|
|
|
+ * @param activeSetting
|
|
|
+ */
|
|
|
+ private void updateProductVoteAndHeat(ActiveHelpRecord activeHelpRecord, ActiveProductRecord activeProductRecord, ActiveSettingDto activeSetting) {
|
|
|
//修改活动热力值和票数
|
|
|
activeProductRecord.setVoteCount(activeProductRecord.getVoteCount() + 1);
|
|
|
+
|
|
|
//判断是否赠送热力值
|
|
|
if (ObjectUtils.isNotEmpty(activeSetting.getVoteAndHeatRate()) && !activeSetting.getVoteAndHeatRate().equals(BigDecimal.ZERO)) {
|
|
|
//查询参赛用户
|
|
|
- LoginUser productUser = loginUserService.getOne(Wrappers.<LoginUser>lambdaQuery().eq(LoginUser::getPhone,activeProductRecord.getPhone()));
|
|
|
+ LoginUser productUser = loginUserService.getOne(Wrappers.<LoginUser>lambdaQuery().eq(LoginUser::getPhone, activeProductRecord.getPhone()));
|
|
|
Assert.notNull(productUser, "没有找到该参赛选手");
|
|
|
|
|
|
//热力值=活动票数*热力值比例
|
|
|
@@ -170,11 +156,59 @@ public class AppActiveProductServiceImpl implements AppActiveProductService {
|
|
|
//修改参赛用户选手信息
|
|
|
Assert.isTrue(loginUserService.updateById(productUser), "投票失败");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //修改活动作品信息
|
|
|
- Assert.isTrue(activeProductRecordService.updateById(activeProductRecord));
|
|
|
+ /**
|
|
|
+ * 更新用户普法积分
|
|
|
+ * @param activeHelpRecord
|
|
|
+ * @param loginUser
|
|
|
+ * @param activeSetting
|
|
|
+ */
|
|
|
+ private void userPuFaPointUpdate(ActiveHelpRecord activeHelpRecord, LoginUser loginUser, ActiveSettingDto activeSetting) {
|
|
|
+ //判断是否普法积分
|
|
|
+ if (ObjectUtils.isNotEmpty(activeSetting.getVoteAndPointRate()) && !activeSetting.getVoteAndPointRate().equals(BigDecimal.ZERO)) {
|
|
|
+ //修改普法积分(票数*积分比例+原有积分)
|
|
|
+ BigDecimal puFaPoint = activeSetting.getVoteAndPointRate()
|
|
|
+ .multiply(BigDecimal.valueOf(activeHelpRecord.getVoteCount()));
|
|
|
+ //添加普法积分赠送记录=>赠送给投票的用户
|
|
|
+ PointRecord pointRecord = new PointRecord();
|
|
|
+ pointRecord.setPoint(BigDecimal.valueOf(puFaPoint.doubleValue())); //必须克隆对象,防止事务状态下,使用同一个对象地址
|
|
|
+ pointRecord.setPointType(PointTypeEnum.PUFA_POINT_SEND);
|
|
|
+ pointRecord.setActiveProductId(activeHelpRecord.getProductId());
|
|
|
+ pointRecord.setUserId(activeHelpRecord.getUserId());
|
|
|
+ Assert.notNull(pointRecordService.save(pointRecord), "投票失败");
|
|
|
+ loginUser.setPufaPoint(puFaPoint.add(loginUser.getPufaPoint()));
|
|
|
+ }
|
|
|
|
|
|
- //添加活动记录
|
|
|
- Assert.isTrue(activeHelpRecordService.save(activeHelpRecord), "投票失败");
|
|
|
+ //修改投票用户信息
|
|
|
+ Assert.isTrue(loginUserService.updateById(loginUser), "投票失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断用户使用该道具对该活动助力次数是否到达上限
|
|
|
+ * @param activeHelpRecord
|
|
|
+ * @param activeProductRecord
|
|
|
+ * @param loginUser
|
|
|
+ * @param helpGoods
|
|
|
+ */
|
|
|
+ private void userHelpCountCheck(ActiveHelpRecord activeHelpRecord, ActiveProductRecord activeProductRecord, LoginUser loginUser, HelpGoods helpGoods) {
|
|
|
+ //判断该用户对该活动助力是否达到上限(-1表示无上限)
|
|
|
+ if (!Long.valueOf(-1).equals(helpGoods.getActiveVote())) {
|
|
|
+ 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, activeProductRecord.getId()) //判断作品ID
|
|
|
+ .eq(ActiveHelpRecord::getUserId, loginUser.getId()) //判断用户ID
|
|
|
+ .eq(ActiveHelpRecord::getHelpGoodsId, helpGoods.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()));
|
|
|
+ if ((MapUtil.getLong(map, "count") + activeHelpRecord.getVoteCount()) > helpGoods.getActiveVote()) {
|
|
|
+ throw new HelpGoodsException("您今日使用该道具对该活动投票次数超过上限");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|