|
@@ -1,15 +1,31 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
+import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.biz.dal.dao.ActivityPlanDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.ActivityPlanEvaluationDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.ActivityPlanDto;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityPlanEvaluation;
|
|
|
+import com.yonge.cooleshow.biz.dal.dto.ActivityPlanPayDto;
|
|
|
+import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
|
|
|
+import com.yonge.cooleshow.biz.dal.dto.search.ActivityPlanSearch;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.ActivityMusicVo;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.ActivityPlanVo;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.MusicActivityVo;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.res.OrderCreateRes;
|
|
|
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.cooleshow.common.enums.ActivityTypeEnum;
|
|
|
import com.yonge.cooleshow.common.enums.RegistrationMethodEnum;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
|
|
@@ -18,10 +34,16 @@ import com.yonge.cooleshow.biz.dal.dto.search.ActivityPlanSearch;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.ActivityPlanDao;
|
|
|
import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -30,7 +52,22 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
|
|
|
@Resource
|
|
|
private ActivityPlanEvaluationDao activityPlanEvaluationDao;
|
|
|
|
|
|
- @Override
|
|
|
+ @Autowired
|
|
|
+ private ActivityEvaluationService activityEvaluationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ActivityRewardService activityRewardService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ActivityRegistrationService activityRegistrationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ActivityEvaluationRecordService activityEvaluationRecordService;
|
|
|
+
|
|
|
+ @Override
|
|
|
public ActivityPlanVo detail(Long id) {
|
|
|
ActivityPlanVo detail = baseMapper.detail(id);
|
|
|
if (null != detail) {
|
|
@@ -116,4 +153,147 @@ public class ActivityPlanServiceImpl extends ServiceImpl<ActivityPlanDao, Activi
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MusicActivityVo getActivityInfo(Long activityPlanId, SysUser user) {
|
|
|
+ ActivityPlan activityPlan = this.getById(activityPlanId);
|
|
|
+
|
|
|
+ MusicActivityVo activityVo = new MusicActivityVo();
|
|
|
+ BeanUtils.copyProperties(activityPlan,activityVo);
|
|
|
+
|
|
|
+ // 活动曲目
|
|
|
+ List<ActivityMusicVo> activityMusicVoList = activityEvaluationService.getActivityMusic(activityPlanId,user.getId());
|
|
|
+ activityVo.setActivityMusicVoList(activityMusicVoList);
|
|
|
+
|
|
|
+ // 报名状态
|
|
|
+ activityVo.setJoin(activityRegistrationService.getRegistration(user.getId(),activityPlanId));
|
|
|
+
|
|
|
+ // 活动奖品
|
|
|
+ List<ActivityReward> activityRewardList = activityRewardService.getActivityReward(activityPlanId);
|
|
|
+ activityVo.setActivityRewardList(activityRewardList);
|
|
|
+
|
|
|
+ // 评测难度
|
|
|
+ String evaluationDifficulty = baseMapper.selectActivityPlanEvaluation(activityPlanId);
|
|
|
+
|
|
|
+ activityVo.setEvaluationDifficulty(evaluationDifficulty);
|
|
|
+ return activityVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResponseResult<OrderCreateRes> orderCreate(OrderReq.OrderReqInfo orderReqInfo) {
|
|
|
+
|
|
|
+ getSysUser(orderReqInfo.getUserId());
|
|
|
+ ActivityPlanPayDto activityPlanPayDto = JSON.parseObject(
|
|
|
+ JSON.toJSONString(orderReqInfo.getBizContent()), ActivityPlanPayDto.class);
|
|
|
+
|
|
|
+ // 检查活动购买
|
|
|
+
|
|
|
+ checkActivityPay(activityPlanPayDto.getActivityId());
|
|
|
+
|
|
|
+
|
|
|
+ if (checkoutJoinActivity(activityPlanPayDto.getActivityId(), orderReqInfo.getUserId())) {
|
|
|
+ throw new BizException("您已经参与了活动");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ OrderCreateRes orderCreateRes = new OrderCreateRes();
|
|
|
+ if (activityPlanPayDto.getActivityId() == null) {
|
|
|
+ throw new BizException("活动id不能为空");
|
|
|
+ }
|
|
|
+ ActivityPlan activityPlan = getById(activityPlanPayDto.getActivityId() );
|
|
|
+
|
|
|
+ orderCreateRes.setRes(true);
|
|
|
+ orderCreateRes.setGoodType(orderCreateRes.getGoodType());
|
|
|
+ orderCreateRes.setBizId(activityPlanPayDto.getActivityId());
|
|
|
+ orderCreateRes.setGoodNum(1);
|
|
|
+ orderCreateRes.setOriginalPrice(activityPlan.getRegistrationPrice());
|
|
|
+ orderCreateRes.setExpectPrice(activityPlan.getRegistrationPrice());
|
|
|
+ return HttpResponseResult.succeed(orderCreateRes);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkoutJoinActivity(Long activityId, Long userId) {
|
|
|
+ return activityRegistrationService.lambdaQuery()
|
|
|
+ .eq(ActivityRegistration::getActivityId, activityId)
|
|
|
+ .eq(ActivityRegistration::getUserId, userId)
|
|
|
+ .count() >0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void orderSuccess(UserOrderDetailVo userOrderDetailVo) {
|
|
|
+ ActivityRegistration activityRegistration = new ActivityRegistration();
|
|
|
+ activityRegistration.setUserId(userOrderDetailVo.getUserId());
|
|
|
+ activityRegistration.setOrderNo(userOrderDetailVo.getOrderNo());
|
|
|
+ activityRegistration.setSubOrderNo(userOrderDetailVo.getSubOrderNo());
|
|
|
+ activityRegistration.setActivityId(userOrderDetailVo.getBizId());
|
|
|
+ activityRegistration.setCreateTime(new Date());
|
|
|
+ activityRegistrationService.save(activityRegistration);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean joinEvaluation(Long evaluationId, SysUser user) {
|
|
|
+ ActivityEvaluation activityEvaluation = activityEvaluationService.getById(evaluationId);
|
|
|
+ if (activityEvaluation == null) {
|
|
|
+ throw new BizException("未找到活动信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ checkActivityPay(activityEvaluation.getActivityId());
|
|
|
+ if (!checkoutJoinActivity(activityEvaluation.getActivityId(),user.getId())) {
|
|
|
+ ActivityPlan activityPlan = this.getById(activityEvaluation.getActivityId());
|
|
|
+ if (RegistrationMethodEnum.FREE.equals(activityPlan.getRegistrationMethod())) {
|
|
|
+
|
|
|
+ // 免费活动 参与时 添加报名记录
|
|
|
+ ActivityRegistration activityRegistration = new ActivityRegistration();
|
|
|
+ activityRegistration.setUserId(user.getId());
|
|
|
+ activityRegistration.setOrderNo(null);
|
|
|
+ activityRegistration.setSubOrderNo(null);
|
|
|
+ activityRegistration.setActivityId(activityEvaluation.getActivityId());
|
|
|
+ activityRegistration.setCreateTime(new Date());
|
|
|
+ activityRegistrationService.save(activityRegistration);
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new BizException("请先报名参与");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> joinEvaluationIdList = activityEvaluationRecordService.getJoinEvaluationIdList(activityEvaluation.getActivityId(),user.getId());
|
|
|
+
|
|
|
+ // 保存参与活动项目记录
|
|
|
+ if (CollectionUtils.isEmpty(joinEvaluationIdList)) {
|
|
|
+ ActivityEvaluationRecord activityEvaluationRecord = new ActivityEvaluationRecord();
|
|
|
+ activityEvaluationRecord.setActivityId(activityEvaluation.getActivityId());
|
|
|
+ activityEvaluationRecord.setUserId(user.getId());
|
|
|
+ activityEvaluationRecord.setEvaluationId(evaluationId);
|
|
|
+ activityEvaluationRecord.setCreateTime(new Date());
|
|
|
+
|
|
|
+ return activityEvaluationRecordService.save(activityEvaluationRecord);
|
|
|
+ }
|
|
|
+ if (!joinEvaluationIdList.contains(evaluationId)) {
|
|
|
+ throw new BizException("已经参与其他项目");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkActivityPay(Long planId) {
|
|
|
+ if (planId == null) {
|
|
|
+ throw new BizException("活动id不能为空");
|
|
|
+ }
|
|
|
+ ActivityPlan activityPlan = getById(planId);
|
|
|
+
|
|
|
+ if (activityPlan.getActivityState() == 0) {
|
|
|
+ throw new BizException("活动已停止");
|
|
|
+ }
|
|
|
+ if (new Date().compareTo(activityPlan.getActivityStart()) <0) {
|
|
|
+ throw new BizException("活动未开始");
|
|
|
+ }
|
|
|
+ if (new Date().compareTo(activityPlan.getActivityEnd()) >0) {
|
|
|
+ throw new BizException("活动已结束");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysUser getSysUser(Long userId) {
|
|
|
+ return Optional.ofNullable(userId)
|
|
|
+ .map(sysUserFeignService::queryUserById)
|
|
|
+ .orElseThrow(() -> new BizException("用户不存在"));
|
|
|
+ }
|
|
|
}
|