| | |
| | | package cn.lili.modules.lmk.service.impl; |
| | | |
| | | import cn.lili.base.Result; |
| | | import cn.lili.common.security.context.UserContext; |
| | | import cn.lili.common.utils.StringUtils; |
| | | import cn.lili.modules.lmk.domain.entity.Activity; |
| | | import cn.lili.modules.lmk.domain.entity.ActivityReport; |
| | | import cn.lili.modules.lmk.domain.form.ActivityReportForm; |
| | | import cn.lili.modules.lmk.domain.query.ActivityReportQuery; |
| | | import cn.lili.modules.lmk.domain.query.MyActivityQuery; |
| | | import cn.lili.modules.lmk.domain.vo.ActivityReportVO; |
| | | import cn.lili.modules.lmk.domain.vo.ActivityVO; |
| | | import cn.lili.modules.lmk.domain.vo.MyActivityVo; |
| | | import cn.lili.modules.lmk.mapper.ActivityMapper; |
| | | import cn.lili.modules.lmk.service.LmkFileService; |
| | | import cn.lili.modules.lmk.mapper.ActivityReportMapper; |
| | | import cn.lili.modules.lmk.service.MyActivityService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xkzhangsan.time.utils.StringUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | @RequiredArgsConstructor |
| | | public class MyActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements MyActivityService { |
| | | private final ActivityMapper activityMapper; |
| | | private final LmkFileService lmkFileService; |
| | | |
| | | private final ActivityReportMapper activityReportMapper; |
| | | |
| | | |
| | | @Override |
| | | public Result getMyActivityList(MyActivityQuery query) { |
| | | List<MyActivityVo> myActivityList = activityMapper.getMyActivityList(query); |
| | | String userId = UserContext.getCurrentUserId(); |
| | | List<MyActivityVo> myActivityList = activityMapper.getMyActivityList(query,userId); |
| | | |
| | | for (MyActivityVo vo : myActivityList) { |
| | | System.out.println(vo); |
| | | if (!"文字".equals(vo.getCoverType())){ |
| | | // String url = lmkFileService.getPreviewUrl(vo.getCover()); |
| | | // vo.setUrl(url); |
| | | } |
| | | } |
| | | return Result.ok().data(myActivityList); |
| | | } |
| | | |
| | | @Override |
| | | public Result cancelActivity(ActivityReportQuery query) { |
| | | public Result activityCancel(String activityId) { |
| | | // TODO 判断是否在报名时间内 在的话可以取消报名, (若有报名费需要退款) |
| | | ActivityReportVO vo = activityMapper.getActivityReport(query); |
| | | //获得中间表信息 |
| | | ActivityReportVO vo = userReport(activityId); |
| | | |
| | | Activity activity = activityMapper.selectById(vo.getActivityId()); |
| | | Activity activity = activityMapper.selectById(activityId); |
| | | |
| | | Date date = new Date(); |
| | | if(!date.before(activity.getReportStartTime()) && !date.after(activity.getReportEndTime())){ |
| | | int affectedRows = activityMapper.cancelActivity(vo.getId()); |
| | | |
| | | if (affectedRows > 0) { |
| | | boolean rowsAffected = new LambdaUpdateChainWrapper<ActivityReport>(activityReportMapper) |
| | | .eq(ActivityReport::getId, vo.getId()) // WHERE id = ? |
| | | .set(ActivityReport::getCancel, true) // SET cancel = true |
| | | .update(); // 执行更新 |
| | | |
| | | |
| | | if (rowsAffected) { |
| | | return Result.ok("活动取消成功"); |
| | | } else { |
| | | // 可选:记录警告日志 |
| | | throw new RuntimeException("活动不存在或已取消"); |
| | | return Result.error("活动不存在或已取消"); |
| | | } |
| | | }else { |
| | | throw new RuntimeException("活动已不在报名时间内无法取消"); |
| | | return Result.error("活动已不在报名时间内无法取消"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public Result activityReport(ActivityReportForm reportActivityForm) { |
| | | //判断用户是否已经报名该活动 |
| | | ActivityReportVO reportVO = userReport(reportActivityForm.getActivityId()); |
| | | if (reportVO != null) { |
| | | //判断是否已取消过该活动 |
| | | if (reportVO.getCancel()){ |
| | | //重新报名 |
| | | |
| | | ActivityReport entity = ActivityReportForm.getEntityByForm(reportActivityForm, null); |
| | | entity.setId(reportVO.getId()); |
| | | entity.setUserId(UserContext.getCurrentUserId()); |
| | | entity.setCancel(false); |
| | | activityReportMapper.updateById(entity); |
| | | return Result.ok("成功"); |
| | | }else { |
| | | return Result.error("该活动已报名"); |
| | | } |
| | | |
| | | |
| | | } |
| | | ActivityReport entity = ActivityReportForm.getEntityByForm(reportActivityForm, null); |
| | | entity.setUserId(UserContext.getCurrentUserId()); |
| | | activityReportMapper.insert(entity); |
| | | return Result.ok("成功"); |
| | | } |
| | | |
| | | /** |
| | | * 获得中间表信息通过activityId,userId |
| | | * @param activityId 活动id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ActivityReportVO userReport(String activityId){ |
| | | |
| | | if (UserContext.getCurrentUserId() == null || UserContext.getCurrentUserId().isEmpty()){ |
| | | throw new RuntimeException("用户登录状态异常"); |
| | | } |
| | | return activityReportMapper.getActivityReport(activityId,UserContext.getCurrentUserId()); |
| | | } |
| | | |
| | | @Override |
| | | public Result detailByUsr(String activityId) { |
| | | ActivityVO vo = baseMapper.getById(activityId); |
| | | Assert.notNull(vo, "记录不存在"); |
| | | |
| | | ActivityReportVO reportVO = userReport(activityId); |
| | | //则当前用户未报名 |
| | | if (reportVO == null){ |
| | | vo.setIsReport(false); |
| | | }else { |
| | | //已取消则可以报名 |
| | | if (reportVO.getCancel()){ |
| | | vo.setIsReport(false); |
| | | }else { |
| | | vo.setIsReport(true); |
| | | } |
| | | |
| | | } |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | |
| | | |
| | | } |